/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.List;
import java.util.Map;
import java.util.Properties;
+
import javax.ws.rs.core.Response;
+
import lombok.NonNull;
+
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
*/
public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
- private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(DatabasePolicyModelsProviderImpl.class);
private final PolicyModelsProviderParameters parameters;
} catch (Exception exc) {
String errorMessage = "could not create Data Access Object (DAO) using url \"" + parameters.getDatabaseUrl()
+ "\" and persistence unit \"" + parameters.getPersistenceUnit() + "\"";
- LOGGER.warn(errorMessage, exc);
this.close();
throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage, exc);
return new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, filter);
}
-
@Override
public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
throws PfModelException {
}
@Override
- public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
- @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput>
+ createGuardPolicy(@NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
assertInitialized();
return new LegacyProvider().createGuardPolicy(pfDao, legacyGuardPolicy);
}
@Override
- public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
- @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
+ public Map<String, LegacyGuardPolicyOutput>
+ updateGuardPolicy(@NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
assertInitialized();
return new LegacyProvider().updateGuardPolicy(pfDao, legacyGuardPolicy);
}
return new PdpProvider().getPdpGroups(pfDao, name);
}
-
@Override
public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
assertInitialized();
return new PdpStatisticsProvider().updatePdpStatistics(pfDao, pdpStatisticsList);
}
-
@Override
public List<PdpStatistics> deletePdpStatistics(@NonNull final String name, final Date timestamp)
throws PfModelException {
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import javax.ws.rs.core.Response;
+
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import lombok.ToString;
+
import org.junit.Test;
/**
public void testFactory() {
PolicyModelsProviderFactory factory = new PolicyModelsProviderFactory();
+ // @formatter:off
assertThatThrownBy(() -> {
factory.createPolicyModelsProvider(null);
- }).hasMessage("parameters is marked @NonNull but is null");
+ }) .hasMessageMatching("^parameters is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation(null);
factory.createPolicyModelsProvider(pars);
- }).hasMessage("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"");
+ }) .hasMessage("could not find implementation of the \"PolicyModelsProvider\" interface \"null\"");
assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("com.acmecorp.RoadRunner");
factory.createPolicyModelsProvider(pars);
- })
- .hasMessage("could not find implementation of the \"PolicyModelsProvider\" "
- + "interface \"com.acmecorp.RoadRunner\"");
+ }) .hasMessage("could not find implementation of the \"PolicyModelsProvider\" "
+ + "interface \"com.acmecorp.RoadRunner\"");
assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("java.lang.String");
factory.createPolicyModelsProvider(pars);
- })
- .hasMessage(
+ }) .hasMessage(
"the class \"java.lang.String\" is not an implementation of the \"PolicyModelsProvider\" interface");
assertThatThrownBy(() -> {
PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
pars.setImplementation("org.onap.policy.models.provider.impl.DummyBadProviderImpl");
factory.createPolicyModelsProvider(pars);
- })
- .hasMessage("could not create an instance of PolicyModelsProvider "
- + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"");
+ }) .hasMessage("could not create an instance of PolicyModelsProvider "
+ + "\"org.onap.policy.models.provider.impl.DummyBadProviderImpl\"");
+ // @formatter:on
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
public class DatabasePolicyModelsProviderTest {
private static final String NAME = "name";
- private static final String TEMPLATE_IS_NULL = "serviceTemplate is marked @NonNull but is null";
+ private static final String TEMPLATE_IS_NULL = "^serviceTemplate is marked .*on.*ull but is null$";
- private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null";
+ private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$";
- private static final String PDP_TYPE_IS_NULL = "pdpType is marked @NonNull but is null";
+ private static final String SUBGROUP_IS_NULL = "^pdpSubGroup is marked .*on.*ull but is null$";
- private static final String SUBGROUP_IS_NULL = "pdpSubGroup is marked @NonNull but is null";
+ private static final String GROUP_IS_NULL = "^pdpGroupName is marked .*on.*ull but is null$";
- private static final String GROUP_IS_NULL = "pdpGroupName is marked @NonNull but is null";
+ private static final String NAME_IS_NULL = "^name is marked .*on.*ull but is null$";
- private static final String NAME_IS_NULL = "name is marked @NonNull but is null";
-
- private static final String FILTER_IS_NULL = "filter is marked @NonNull but is null";
-
- private static final String INSTANCE = "Instance";
+ private static final String FILTER_IS_NULL = "^filter is marked .*on.*ull but is null$";
private static final String POLICY_ID = "policy_id";
public void testInitAndClose() throws Exception {
assertThatThrownBy(() -> {
new DatabasePolicyModelsProviderImpl(null);
- }).hasMessage("parameters is marked @NonNull but is null");
+ }).hasMessageMatching("^parameters is marked .*on.*ull but is null$");
PolicyModelsProvider databaseProvider =
new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
public void testProviderMethodsNull() throws Exception {
try (PolicyModelsProvider databaseProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
assertThatThrownBy(() -> {
databaseProvider.getFilteredPolicyTypes(null);
- }).hasMessage(FILTER_IS_NULL);
+ }).hasMessageMatching(FILTER_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getFilteredPolicyTypeList(null);
- }).hasMessage(FILTER_IS_NULL);
+ }).hasMessageMatching(FILTER_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.createPolicyTypes(null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePolicyTypes(null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deletePolicyType(null, null);
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deletePolicyType("aaa", null);
- }).hasMessage("version is marked @NonNull but is null");
+ }).hasMessageMatching("^version is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.deletePolicyType(null, "aaa");
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getFilteredPolicies(null);
- }).hasMessage(FILTER_IS_NULL);
+ }).hasMessageMatching(FILTER_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getFilteredPolicyList(null);
- }).hasMessage(FILTER_IS_NULL);
+ }).hasMessageMatching(FILTER_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.createPolicies(null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePolicies(null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deletePolicy(null, null);
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deletePolicy(null, "aaa");
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deletePolicy("aaa", null);
- }).hasMessage("version is marked @NonNull but is null");
+ }).hasMessageMatching("^version is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.getOperationalPolicy(null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getOperationalPolicy(null, "");
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getOperationalPolicy("", null);
assertThatThrownBy(() -> {
databaseProvider.createOperationalPolicy(null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.updateOperationalPolicy(null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.deleteOperationalPolicy(null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deleteOperationalPolicy(null, "");
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deleteOperationalPolicy("", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.getGuardPolicy(null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getGuardPolicy(null, "");
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getGuardPolicy("", null);
assertThatThrownBy(() -> {
databaseProvider.createGuardPolicy(null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("^legacyGuardPolicy is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.updateGuardPolicy(null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("^legacyGuardPolicy is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.deleteGuardPolicy(null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deleteGuardPolicy(null, "");
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deleteGuardPolicy("", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.getFilteredPdpGroups(null);
- }).hasMessage(FILTER_IS_NULL);
+ }).hasMessageMatching(FILTER_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.createPdpGroups(null);
- }).hasMessage("pdpGroups is marked @NonNull but is null");
+ }).hasMessageMatching("^pdpGroups is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.updatePdpGroups(null);
- }).hasMessage("pdpGroups is marked @NonNull but is null");
+ }).hasMessageMatching("^pdpGroups is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.updatePdpSubGroup(null, null);
- }).hasMessage(GROUP_IS_NULL);
+ }).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdpSubGroup(null, new PdpSubGroup());
- }).hasMessage(GROUP_IS_NULL);
+ }).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdpSubGroup(NAME, null);
- }).hasMessage(SUBGROUP_IS_NULL);
+ }).hasMessageMatching(SUBGROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdpSubGroup(NAME, new PdpSubGroup());
assertThatThrownBy(() -> {
databaseProvider.updatePdp(null, null, null);
- }).hasMessage(GROUP_IS_NULL);
+ }).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdp(null, null, new Pdp());
- }).hasMessage(GROUP_IS_NULL);
+ }).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdp(null, "sub", null);
- }).hasMessage(GROUP_IS_NULL);
+ }).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdp(null, "sub", new Pdp());
- }).hasMessage(GROUP_IS_NULL);
+ }).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdp(NAME, null, null);
- }).hasMessage(SUBGROUP_IS_NULL);
+ }).hasMessageMatching(SUBGROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdp(NAME, null, new Pdp());
- }).hasMessage(SUBGROUP_IS_NULL);
+ }).hasMessageMatching(SUBGROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updatePdp(NAME, "sub", null);
- }).hasMessage("pdp is marked @NonNull but is null");
+ }).hasMessageMatching("^pdp is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.updatePdp(NAME, "sub", new Pdp());
assertThatThrownBy(() -> {
databaseProvider.deletePdpGroup(null);
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.getFilteredPdpStatistics(NAME, null, "sub", TIMESTAMP, TIMESTAMP);
- }).hasMessage(GROUP_IS_NULL);
+ }).hasMessageMatching(GROUP_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.createPdpStatistics(null);
- }).hasMessage("pdpStatisticsList is marked @NonNull but is null");
+ }).hasMessageMatching("^pdpStatisticsList is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.updatePdpStatistics(null);
- }).hasMessage("pdpStatisticsList is marked @NonNull but is null");
+ }).hasMessageMatching("^pdpStatisticsList is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
databaseProvider.deletePdpStatistics(null, TIMESTAMP);
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
}
}
assertThatThrownBy(() -> {
databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy());
- }).hasMessage(NAME_IS_NULL);
+ }).hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> {
databaseProvider.deleteOperationalPolicy(POLICY_ID, "55");
pdpSubGroup.setDesiredInstanceCount(234);
databaseProvider.updatePdpSubGroup(GROUP, pdpSubGroup);
- assertEquals(234, databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
- .get(0).getDesiredInstanceCount());
+ assertEquals(234,
+ databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
- assertEquals("Hello", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
- .get(0).getPdpInstances().get(0).getMessage());
+ assertEquals("Hello", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups().get(0).getPdpInstances()
+ .get(0).getMessage());
pdp.setMessage("Howdy");
databaseProvider.updatePdp(GROUP, "type", pdp);
- assertEquals("Howdy", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups()
- .get(0).getPdpInstances().get(0).getMessage());
+ assertEquals("Howdy", databaseProvider.getPdpGroups(GROUP).get(0).getPdpSubgroups().get(0).getPdpInstances()
+ .get(0).getMessage());
assertThatThrownBy(() -> {
databaseProvider.deletePdpGroup(NAME);
assertEquals(pdpGroup.getName(), databaseProvider.deletePdpGroup(GROUP).getName());
- assertEquals(0, databaseProvider.getPdpStatistics(null,null).size());
+ assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
- databaseProvider.getFilteredPdpStatistics(null, GROUP,null, null, null);
- databaseProvider.getFilteredPdpStatistics(null, GROUP,null, new Date(), null);
- databaseProvider.getFilteredPdpStatistics(null, GROUP,null, null, new Date());
- databaseProvider.getFilteredPdpStatistics(null, GROUP,null, new Date(), new Date());
+ databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, null);
+ databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), null);
+ databaseProvider.getFilteredPdpStatistics(null, GROUP, null, null, new Date());
+ databaseProvider.getFilteredPdpStatistics(null, GROUP, null, new Date(), new Date());
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP,null, null, null);
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP,null, new Date(), new Date());
+ databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, null, null);
+ databaseProvider.getFilteredPdpStatistics(NAME, GROUP, null, new Date(), new Date());
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP,"type", null, null);
- databaseProvider.getFilteredPdpStatistics(NAME, GROUP,"type", new Date(), new Date());
+ databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", null, null);
+ databaseProvider.getFilteredPdpStatistics(NAME, GROUP, "type", new Date(), new Date());
databaseProvider.createPdpStatistics(statisticsArrayList);
databaseProvider.updatePdpStatistics(statisticsArrayList);
- databaseProvider.deletePdpStatistics("pdp1",null);
+ databaseProvider.deletePdpStatistics("pdp1", null);
} catch (Exception exc) {
LOGGER.warn("test should not throw an exception", exc);
fail("test should not throw an exception");
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
+
import org.junit.Test;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
-import org.onap.policy.models.pdp.concepts.PdpStatistics;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
parameters.setPersistenceUnit("dummy");
try (PolicyModelsProvider dummyProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
dummyProvider.init();
parameters.setPersistenceUnit("dummy");
try (PolicyModelsProvider dummyProvider =
- new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) {
dummyProvider.init();
assertNotNull(dummyProvider.getPolicyTypes("name", VERSION));
@Test
public void testDummyResponse() {
try (DummyPolicyModelsProviderSubImpl resp =
- new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
+ new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
assertThatThrownBy(resp::getBadDummyResponse1).hasMessage("error serializing object");
}
try (DummyPolicyModelsProviderSubImpl resp =
- new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
+ new DummyPolicyModelsProviderSubImpl(new PolicyModelsProviderParameters())) {
assertThatThrownBy(resp::getBadDummyResponse2).hasMessage("error serializing object");
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import java.util.TreeMap;
import lombok.NonNull;
+
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.dao.PfDao;
LOGGER.debug("->getPolicyTypes: name={}, version={}", name, version);
- ToscaServiceTemplate serviceTemplate =
- new SimpleToscaProvider().getPolicyTypes(dao, name, version).toAuthorative();
+ JpaToscaServiceTemplate jpaServiceTemplate = new SimpleToscaProvider().getPolicyTypes(dao, name, version);
+
+ ToscaServiceTemplate serviceTemplate = jpaServiceTemplate.toAuthorative();
LOGGER.debug("<-getPolicyTypes: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate);
return serviceTemplate;
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.dao.PfDao;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
public class SimpleToscaProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(SimpleToscaProvider.class);
+ /**
+ * Get data types.
+ *
+ * @param dao the DAO to use to access the database
+ * @param name the name of the data type to get, set to null to get all policy types
+ * @param version the version of the data type to get, set to null to get all versions
+ * @return the data types found
+ * @throws PfModelException on errors getting data types
+ */
+ public JpaToscaServiceTemplate getDataTypes(@NonNull final PfDao dao, final String name, final String version)
+ throws PfModelException {
+ LOGGER.debug("->getDataTypes: name={}, version={}", name, version);
+
+ // Create the structure of the TOSCA service template to contain the data type
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+ serviceTemplate.setDataTypes(new JpaToscaDataTypes());
+
+ // Add the data type to the TOSCA service template
+ List<JpaToscaDataType> jpaDataTypeList = dao.getFiltered(JpaToscaDataType.class, name, version);
+ serviceTemplate.getDataTypes().getConceptMap().putAll(asConceptMap(jpaDataTypeList));
+
+ LOGGER.debug("<-getDataTypes: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate);
+ return serviceTemplate;
+ }
+
+ /**
+ * Create data types.
+ *
+ * @param dao the DAO to use to access the database
+ * @param serviceTemplate the service template containing the definition of the data types to be created
+ * @return the TOSCA service template containing the created data types
+ * @throws PfModelException on errors creating data types
+ */
+ public JpaToscaServiceTemplate createDataTypes(@NonNull final PfDao dao,
+ @NonNull final JpaToscaServiceTemplate serviceTemplate) throws PfModelException {
+ LOGGER.debug("->createDataTypes: serviceTempalate={}", serviceTemplate);
+
+ ToscaUtils.assertDataTypesExist(serviceTemplate);
+
+ for (JpaToscaDataType dataType : serviceTemplate.getDataTypes().getAll(null)) {
+ dao.create(dataType);
+ }
+
+ // Return the created Data types
+ JpaToscaDataTypes returnDataTypes = new JpaToscaDataTypes();
+
+ for (PfConceptKey dataTypeKey : serviceTemplate.getDataTypes().getConceptMap().keySet()) {
+ returnDataTypes.getConceptMap().put(dataTypeKey, dao.get(JpaToscaDataType.class, dataTypeKey));
+ }
+
+ JpaToscaServiceTemplate returnServiceTemplate = new JpaToscaServiceTemplate();
+ returnServiceTemplate.setDataTypes(returnDataTypes);
+
+ LOGGER.debug("<-createDataTypes: returnServiceTempalate={}", returnServiceTemplate);
+ return returnServiceTemplate;
+ }
+
+ /**
+ * Update Data types.
+ *
+ * @param dao the DAO to use to access the database
+ * @param serviceTemplate the service template containing the definition of the data types to be modified
+ * @return the TOSCA service template containing the modified data types
+ * @throws PfModelException on errors updating Data types
+ */
+ public JpaToscaServiceTemplate updateDataTypes(@NonNull final PfDao dao,
+ @NonNull final JpaToscaServiceTemplate serviceTemplate) throws PfModelException {
+ LOGGER.debug("->updateDataTypes: serviceTempalate={}", serviceTemplate);
+
+ ToscaUtils.assertDataTypesExist(serviceTemplate);
+
+ for (JpaToscaDataType dataType : serviceTemplate.getDataTypes().getAll(null)) {
+ dao.update(dataType);
+ }
+
+ // Return the created data types
+ JpaToscaDataTypes returnDataTypes = new JpaToscaDataTypes();
+
+ for (PfConceptKey dataTypeKey : serviceTemplate.getDataTypes().getConceptMap().keySet()) {
+ returnDataTypes.getConceptMap().put(dataTypeKey, dao.get(JpaToscaDataType.class, dataTypeKey));
+ }
+
+ JpaToscaServiceTemplate returnServiceTemplate = new JpaToscaServiceTemplate();
+ returnServiceTemplate.setDataTypes(returnDataTypes);
+
+ LOGGER.debug("<-updateDataTypes: returnServiceTempalate={}", returnServiceTemplate);
+ return returnServiceTemplate;
+ }
+
+ /**
+ * Delete Data types.
+ *
+ * @param dao the DAO to use to access the database
+ * @param dataTypeKey the data type key for the Data types to be deleted, if the version of the key is null, all
+ * versions of the data type are deleted.
+ * @return the TOSCA service template containing the data types that were deleted
+ * @throws PfModelException on errors deleting data types
+ */
+ public JpaToscaServiceTemplate deleteDataType(@NonNull final PfDao dao, @NonNull final PfConceptKey dataTypeKey)
+ throws PfModelException {
+ LOGGER.debug("->deleteDataType: key={}", dataTypeKey);
+
+ JpaToscaServiceTemplate serviceTemplate = getDataTypes(dao, dataTypeKey.getName(), dataTypeKey.getVersion());
+
+ dao.delete(JpaToscaDataType.class, dataTypeKey);
+
+ LOGGER.debug("<-deleteDataType: key={}, serviceTempalate={}", dataTypeKey, serviceTemplate);
+ return serviceTemplate;
+ }
+
/**
* Get policy types.
*
List<JpaToscaPolicyType> jpaPolicyTypeList = dao.getFiltered(JpaToscaPolicyType.class, name, version);
serviceTemplate.getPolicyTypes().getConceptMap().putAll(asConceptMap(jpaPolicyTypeList));
- LOGGER.debug("<-getPolicyTypes: name={}, version={}, serviceTemplate=", name, version, serviceTemplate);
+ LOGGER.debug("<-getPolicyTypes: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate);
return serviceTemplate;
}
}
/**
- * Create policy types.
+ * Update policy types.
*
* @param dao the DAO to use to access the database
* @param serviceTemplate the service template containing the definition of the policy types to be modified
dao.delete(JpaToscaPolicyType.class, policyTypeKey);
- LOGGER.debug("<-deletePolicyType: key={}, serviceTempalate=", policyTypeKey, serviceTemplate);
+ LOGGER.debug("<-deletePolicyType: key={}, serviceTempalate={}", policyTypeKey, serviceTemplate);
return serviceTemplate;
}
List<JpaToscaPolicy> jpaPolicyList = dao.getFiltered(JpaToscaPolicy.class, name, version);
serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().putAll(asConceptMap(jpaPolicyList));
- LOGGER.debug("<-getPolicies: name={}, version={}, serviceTemplate=", name, version, serviceTemplate);
+ LOGGER.debug("<-getPolicies: name={}, version={}, serviceTemplate={}", name, version, serviceTemplate);
return serviceTemplate;
}
dao.delete(JpaToscaPolicy.class, policyKey);
- LOGGER.debug("<-deletePolicy: key={}, serviceTempalate=", policyKey, serviceTemplate);
+ LOGGER.debug("<-deletePolicy: key={}, serviceTempalate={}", policyKey, serviceTemplate);
return serviceTemplate;
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
}
/**
- * Check if policy types have been specified is initialized.
+ * Check if data types have been specified correctly.
+ *
+ * @param serviceTemplate the service template containing data types to be checked
+ */
+ public static void assertDataTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
+ if (serviceTemplate.getDataTypes() == null) {
+ String errorMessage = "no data types specified on service template";
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ }
+
+ if (serviceTemplate.getDataTypes().getConceptMap().isEmpty()) {
+ String errorMessage = "list of data types specified on service template is empty";
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ }
+ }
+
+ /**
+ * Check if policy types have been specified correctly.
+ *
+ * @param serviceTemplate the service template containing policy types to be checked
*/
public static void assertPolicyTypesExist(final JpaToscaServiceTemplate serviceTemplate) {
if (serviceTemplate.getPolicyTypes() == null) {
}
/**
- * Check if policy types have been specified is initialized.
+ * Check if policies have been specified correctly.
+ *
+ * @param serviceTemplate the service template containing policy types to be checked
*/
public static void assertPoliciesExist(final JpaToscaServiceTemplate serviceTemplate) {
if (serviceTemplate.getTopologyTemplate() == null) {
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
private static final String VCPE_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
private static final String POLICY_AND_VERSION = "onap.restart.tca:1.0.0";
private static final String POLICY1 = "onap.restart.tca";
- private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
private static final String VERSION_100 = "1.0.0";
private PfDao pfDao;
private StandardCoder standardCoder;
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicies(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicyList(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
createPolicyTypes();
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
- List<ToscaPolicy> gotPolicyList =
- new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
+ List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
public void testPoliciesGetFiltered() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicies(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null);
- }).hasMessage("filter is marked @NonNull but is null");
+ }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyList(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null);
- }).hasMessage("filter is marked @NonNull but is null");
+ }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
createPolicyTypes();
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
- List<ToscaPolicy> gotPolicyList =
- new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
+ List<ToscaPolicy> gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
public void testPolicyCreate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
createPolicyTypes();
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicies(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicies(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
createPolicyTypes();
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(null, null, VERSION);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(null, "name", null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(pfDao, null, null);
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessageMatching("^name is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION);
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessageMatching("^name is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
- }).hasMessage("version is marked @NonNull but is null");
+ }).hasMessageMatching("^version is marked .*on.*ull but is null$");
createPolicyTypes();
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_JSON), ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
- }).hasMessage("version is marked @NonNull but is null");
+ }).hasMessageMatching("^version is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import static org.junit.Assert.assertTrue;
import com.google.gson.GsonBuilder;
+
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Properties;
+
import org.apache.commons.lang3.ObjectUtils;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
private static final String POLICY_AFFINITY_VERSION0 = "onap.policies.NoVersion:0.0.0";
private static final String POLICY_AFFINITY = "onap.policies.NoVersion";
private static final String MISSING_POLICY_TYPES = "no policy types specified on service template";
- private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
private static final String VERSION_000 = "0.0.0";
private static String yamlAsJsonString;
private PfDao pfDao;
private StandardCoder standardCoder;
-
/**
* Read the policy type definition.
*
*/
@BeforeClass
public static void readPolicyDefinition() {
- String yamlString =
- ResourceUtils.getResourceAsString("src/test/resources/onap.policies.NoVersion.yaml");
+ String yamlString = ResourceUtils.getResourceAsString("src/test/resources/onap.policies.NoVersion.yaml");
Object yamlObject = new Yaml().load(yamlString);
yamlAsJsonString = new GsonBuilder().setPrettyPrinting().create().toJson(yamlObject);
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb");
- daoParameters.setJdbcProperties(jdbcProperties );
+ daoParameters.setJdbcProperties(jdbcProperties);
pfDao = new PfDaoFactory().createPfDao(daoParameters);
pfDao.init(daoParameters);
public void testPolicyTypesGet() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicyTypes(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicyList(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
- List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
- POLICY_AFFINITY, VERSION_000);
+ List<ToscaPolicyType> gotPolicyTypeList =
+ new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, VERSION_000);
assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
- gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
- POLICY_AFFINITY, null);
+ gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, null);
assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
}
-
@Test
public void testPolicyTypesGetFiltered() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypes(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypes(null, ToscaPolicyTypeFilter.builder().build());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, null);
- }).hasMessage("filter is marked @NonNull but is null");
+ }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, ToscaPolicyTypeFilter.builder().build());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null);
- }).hasMessage("filter is marked @NonNull but is null");
+ }).hasMessageMatching("^filter is marked .*on.*ull but is null$");
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
- List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
- POLICY_AFFINITY, VERSION_000);
+ List<ToscaPolicyType> gotPolicyTypeList =
+ new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_AFFINITY, VERSION_000);
assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
public void testPolicyTypesCreate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(null, new ToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
ToscaServiceTemplate testToscaServiceTemplate = new ToscaServiceTemplate();
assertThatThrownBy(() -> {
public void testPolicyTypesUpdate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicyTypes(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicyTypes(null, new ToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicyTypes(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
public void testPolicyTypesDelete() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(null, null, VERSION);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(null, "name", null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(null, "name", VERSION);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(pfDao, null, null);
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessageMatching("^name is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(pfDao, null, VERSION);
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessageMatching("^name is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null);
- }).hasMessage("version is marked @NonNull but is null");
+ }).hasMessageMatching("^version is marked .*on.*ull but is null$");
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(pfDao, "name", null);
- }).hasMessage("version is marked @NonNull but is null");
+ }).hasMessageMatching("^version is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate);
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class LegacyProvider4LegacyGuardTest {
- private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null";
+ private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$";
private static final String VDNS_OUTPUT_JSON = "policies/vDNS.policy.guard.frequency.output.json";
private static final String VDNS_INPUT_JSON = "policies/vDNS.policy.guard.frequency.input.json";
- private static final String LEGACY_POLICY_IS_NULL = "legacyGuardPolicy is marked @NonNull but is null";
- private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String LEGACY_POLICY_IS_NULL = "^legacyGuardPolicy is marked .*on.*ull but is null$";
+ private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
private PfDao pfDao;
private StandardCoder standardCoder;
-
/**
* Set up the DAO towards the database.
*
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(null, null, "");
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(pfDao, null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist", null);
createPolicyTypes();
- LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
- LegacyGuardPolicyInput.class);
+ LegacyGuardPolicyInput originalGip =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
assertEquals(originalGip.getContent(),
gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
- String expectedJsonOutput =
- ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
+ String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotGopm);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
public void testPolicyCreate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(pfDao, null);
- }).hasMessage(LEGACY_POLICY_IS_NULL);
+ }).hasMessageMatching(LEGACY_POLICY_IS_NULL);
createPolicyTypes();
- LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
- LegacyGuardPolicyInput.class);
+ LegacyGuardPolicyInput originalGip =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
assertEquals(originalGip.getContent(),
gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
- String expectedJsonOutput =
- ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
+ String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotGopm);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
public void testPolicyCreateBad() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(pfDao, null);
- }).hasMessage(LEGACY_POLICY_IS_NULL);
+ }).hasMessageMatching(LEGACY_POLICY_IS_NULL);
createPolicyTypes();
- LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
- LegacyGuardPolicyInput.class);
+ LegacyGuardPolicyInput originalGip =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(null, new LegacyGuardPolicyInput());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(pfDao, null);
- }).hasMessage(LEGACY_POLICY_IS_NULL);
+ }).hasMessageMatching(LEGACY_POLICY_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(pfDao, new LegacyGuardPolicyInput());
createPolicyTypes();
- LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
- LegacyGuardPolicyInput.class);
+ LegacyGuardPolicyInput originalGip =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
gotUpdatedGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next().getRecipe());
}
-
@Test
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, null, "");
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, "", null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, "", "");
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, null, "");
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, "", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, "IDontExist", "0");
createPolicyTypes();
- LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
- LegacyGuardPolicyInput.class);
+ LegacyGuardPolicyInput originalGip =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VDNS_INPUT_JSON), LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
assertEquals(originalGip.getContent(),
gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
- String expectedJsonOutput =
- ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
+ String expectedJsonOutput = ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotGopm);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
Map<String, LegacyGuardPolicyOutput> deletedGopm =
new LegacyProvider().deleteGuardPolicy(pfDao, originalGip.getPolicyId(), "1");
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class LegacyProvider4LegacyOperationalTest {
- private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null";
+ private static final String POLICY_ID_IS_NULL = "^policyId is marked .*on.*ull but is null$";
private static final String VCPE_OUTPUT_JSON = "policies/vCPE.policy.operational.output.json";
private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.operational.input.json";
- private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
private PfDao pfDao;
private StandardCoder standardCoder;
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(null, "", null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(pfDao, null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist", null);
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- LegacyOperationalPolicy.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class);
assertNotNull(originalLop);
public void testPolicyCreate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().createOperationalPolicy(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createOperationalPolicy(null, new LegacyOperationalPolicy());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createOperationalPolicy(pfDao, null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- LegacyOperationalPolicy.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class);
assertNotNull(originalLop);
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(null, new LegacyOperationalPolicy());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(pfDao, null);
- }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("^legacyOperationalPolicy is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(pfDao, new LegacyOperationalPolicy());
- }).hasMessage("name is marked @NonNull but is null");
+ }).hasMessageMatching("^name is marked .*on.*ull but is null$");
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- LegacyOperationalPolicy.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class);
assertNotNull(originalLop);
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, null, "");
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, "", null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, "", "");
-
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, null, null);
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, null, "");
- }).hasMessage(POLICY_ID_IS_NULL);
+ }).hasMessageMatching(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, "", null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, "IDontExist", "0");
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- LegacyOperationalPolicy.class);
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), LegacyOperationalPolicy.class);
assertNotNull(originalLop);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, originalLop.getPolicyId(), null);
- }).hasMessage("policyVersion is marked @NonNull but is null");
+ }).hasMessageMatching("^policyVersion is marked .*on.*ull but is null$");
LegacyOperationalPolicy deletedLop =
new LegacyProvider().deleteOperationalPolicy(pfDao, originalLop.getPolicyId(), "1");
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import static org.junit.Assert.assertTrue;
import java.util.Properties;
+
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
import org.onap.policy.models.dao.impl.DefaultPfDao;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class SimpleToscaProviderTest {
- private static final String TEMPLATE_IS_NULL = "serviceTemplate is marked @NonNull but is null";
+ private static final String TEMPLATE_IS_NULL = "^serviceTemplate is marked .*on.*ull but is null$";
private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
- private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String DAO_IS_NULL = "^dao is marked .*on.*ull but is null$";
private PfDao pfDao;
private StandardCoder standardCoder;
pfDao.close();
}
+ @Test
+ public void testCreateUpdateGetDeleteDataType() throws PfModelException {
+ JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
+
+ PfConceptKey dataType0Key = new PfConceptKey("DataType0", "0.0.1");
+ JpaToscaDataType dataType0 = new JpaToscaDataType();
+ dataType0.setKey(dataType0Key);
+ serviceTemplate.setDataTypes(new JpaToscaDataTypes());
+ serviceTemplate.getDataTypes().getConceptMap().put(dataType0Key, dataType0);
+
+ JpaToscaServiceTemplate createdServiceTemplate =
+ new SimpleToscaProvider().createDataTypes(pfDao, serviceTemplate);
+
+ assertEquals(dataType0, createdServiceTemplate.getDataTypes().get(dataType0Key));
+ assertEquals(null, createdServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+
+ dataType0.setDescription("Updated Description");
+
+ JpaToscaServiceTemplate updatedServiceTemplate =
+ new SimpleToscaProvider().updateDataTypes(pfDao, serviceTemplate);
+
+ assertEquals(dataType0, updatedServiceTemplate.getDataTypes().get(dataType0Key));
+ assertEquals("Updated Description", updatedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+
+ JpaToscaServiceTemplate gotServiceTemplate =
+ new SimpleToscaProvider().getDataTypes(pfDao, dataType0Key.getName(), dataType0Key.getVersion());
+
+ assertEquals(dataType0, gotServiceTemplate.getDataTypes().get(dataType0Key));
+ assertEquals("Updated Description", gotServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+
+ JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
+
+ assertEquals(dataType0, deletedServiceTemplate.getDataTypes().get(dataType0Key));
+ assertEquals("Updated Description", deletedServiceTemplate.getDataTypes().get(dataType0Key).getDescription());
+
+ JpaToscaServiceTemplate doesNotExistServiceTemplate =
+ new SimpleToscaProvider().deleteDataType(pfDao, dataType0Key);
+
+ assertEquals(null, doesNotExistServiceTemplate.getDataTypes().get(dataType0Key));
+ }
+
@Test
public void testPoliciesGet() throws Exception {
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
@Test
public void testPolicyCreate() throws Exception {
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
@Test
public void testPolicyUpdate() throws Exception {
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
@Test
public void testPoliciesDelete() throws Exception {
- ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
- ToscaServiceTemplate.class);
+ ToscaServiceTemplate toscaServiceTemplate =
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON), ToscaServiceTemplate.class);
createPolicyTypes();
JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate();
assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
- .hasMessage("topology template not specified on service template");
+ .hasMessage("topology template not specified on service template");
testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
- .hasMessage("no policies specified on topology template of service template");
+ .hasMessage("no policies specified on topology template of service template");
testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
- .hasMessage("list of policies specified on topology template of service template is empty");
+ .hasMessage("list of policies specified on topology template of service template is empty");
}
@Test
public void testNonNulls() {
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().getDataTypes(null, null, null);
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().createDataTypes(null, null);
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().createDataTypes(null, new JpaToscaServiceTemplate());
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().createDataTypes(pfDao, null);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().updateDataTypes(null, null);
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().updateDataTypes(null, new JpaToscaServiceTemplate());
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().updateDataTypes(pfDao, null);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().deleteDataType(null, null);
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().deleteDataType(null, new PfConceptKey());
+ }).hasMessageMatching(DAO_IS_NULL);
+
+ assertThatThrownBy(() -> {
+ new SimpleToscaProvider().deleteDataType(pfDao, null);
+ }).hasMessageMatching("^dataTypeKey is marked .*on.*ull but is null$");
+
assertThatThrownBy(() -> {
new SimpleToscaProvider().getPolicyTypes(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicyTypes(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicyTypes(pfDao, null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicyTypes(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicyTypes(pfDao, null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicyType(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicyType(pfDao, null);
- }).hasMessage("policyTypeKey is marked @NonNull but is null");
+ }).hasMessageMatching("^policyTypeKey is marked .*on.*ull but is null$");
assertThatThrownBy(() -> {
new SimpleToscaProvider().getPolicies(null, null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(pfDao, null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicies(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicies(pfDao, null);
- }).hasMessage(TEMPLATE_IS_NULL);
+ }).hasMessageMatching(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicy(null, null);
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicy(null, new PfConceptKey());
- }).hasMessage(DAO_IS_NULL);
+ }).hasMessageMatching(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicy(pfDao, null);
- }).hasMessage("policyKey is marked @NonNull but is null");
+ }).hasMessageMatching("^policyKey is marked .*on.*ull but is null$");
}
private void createPolicyTypes() throws CoderException, PfModelException {
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.models.tosca.utils;
+import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
+import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
/**
* Import the {@link ToscaUtils} class.
public class ToscaUtilsTest {
@Test
- public void test() {
+ public void testAssertDataTypes() {
JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
+ }).hasMessage("no data types specified on service template");
+
+ jpaToscaServiceTemplate.setDataTypes(new JpaToscaDataTypes());
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
+ }).hasMessage("list of data types specified on service template is empty");
+
+ jpaToscaServiceTemplate.getDataTypes().getConceptMap().put(new PfConceptKey(), null);
+
+ assertThatCode(() -> {
+ ToscaUtils.assertDataTypesExist(jpaToscaServiceTemplate);
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testAssertPolicyTypes() {
+ JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
+ }).hasMessage("no policy types specified on service template");
+
jpaToscaServiceTemplate.setPolicyTypes(new JpaToscaPolicyTypes());
assertThatThrownBy(() -> {
ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
}).hasMessage("list of policy types specified on service template is empty");
+
+ jpaToscaServiceTemplate.getPolicyTypes().getConceptMap().put(new PfConceptKey(), null);
+
+ assertThatCode(() -> {
+ ToscaUtils.assertPolicyTypesExist(jpaToscaServiceTemplate);
+ }).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testAssertPolicies() {
+ JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate();
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
+ }).hasMessage("topology template not specified on service template");
+
+ jpaToscaServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
+ }).hasMessage("no policies specified on topology template of service template");
+
+ jpaToscaServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
+ }).hasMessage("list of policies specified on topology template of service template is empty");
+
+ jpaToscaServiceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(new PfConceptKey(), null);
+
+ assertThatCode(() -> {
+ ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
+ }).doesNotThrowAnyException();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START=======================================================
- Copyright (C) 2019 Nordix Foundation.
+ Copyright (C) 2019-2020 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
-
+
http://www.apache.org/licenses/LICENSE-2.0
-
+
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-
+
SPDX-License-Identifier: Apache-2.0
============LICENSE_END=========================================================
-->
<class>org.onap.policy.models.base.PfConceptKey</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
<class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
+ <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType</class>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />