private static final String NAME_TOKEN = "name";
private static final String VERSION_TOKEN = "version";
- @Column(name = NAME_TOKEN, length = 128)
+ @Column(name = NAME_TOKEN, length = 120)
private String name;
- @Column(name = VERSION_TOKEN, length = 128)
+ @Column(name = VERSION_TOKEN, length = 20)
private String version;
/**
* Check if a value matches a regular expression.
*
* @param value the incoming value to check
- * @param regexp the regular expression to check against
+ * @param pattern the pattern to check against
* @return match or not
*/
- public default boolean filterOnRegexp(@NonNull final String value, @NonNull final String regexp) {
- return value.matches(regexp);
+ public default boolean filterString(@NonNull final String value, final String pattern) {
+ return pattern == null || value.equals(pattern);
}
/**
T lastElement = filteredList.get(j);
/*
- * The list is sorted so if the last element name is the same as the current
- * element name, the current element should be removed.
+ * The list is sorted so if the last element name is the same as the current element name, the current
+ * element should be removed.
*/
- if (!((PfNameVersion)curElement).getName().equals(((PfNameVersion)lastElement).getName())) {
+ if (!((PfNameVersion) curElement).getName().equals(((PfNameVersion) lastElement).getName())) {
// have a new name - done comparing with the old "current"
++icur;
}
private static final int PARENT_LOCAL_NAME_FIELD = 2;
private static final int LOCAL_NAME_FIELD = 3;
- @Column(name = PARENT_KEY_NAME, length = 128)
+ @Column(name = PARENT_KEY_NAME, length = 120)
private String parentKeyName;
- @Column(name = PARENT_KEY_VERSION, length = 128)
+ @Column(name = PARENT_KEY_VERSION, length = 15)
private String parentKeyVersion;
- @Column(name = PARENT_LOCAL_NAME, length = 128)
+ @Column(name = PARENT_LOCAL_NAME, length = 120)
private String parentLocalName;
- @Column(name = LOCAL_NAME, length = 128)
+ @Column(name = LOCAL_NAME, length = 120)
private String localName;
/**
doList.add(do5);
DummyPfObjectFilter dof = new DummyPfObjectFilter();
- assertFalse(dof.filterOnRegexp("Hello", "Goodbye"));
- assertTrue(dof.filterOnRegexp("Hello", "Hello"));
+ assertFalse(dof.filterString("Hello", "Goodbye"));
+ assertTrue(dof.filterString("Hello", "Hello"));
assertThatThrownBy(() -> {
- dof.filterOnRegexp(null, null);
+ dof.filterString(null, null);
}).hasMessage("value is marked @NonNull but is null");
assertThatThrownBy(() -> {
- dof.filterOnRegexp("hello", null);
- }).hasMessage("regexp is marked @NonNull but is null");
-
- assertThatThrownBy(() -> {
- dof.filterOnRegexp(null, "hello");
+ dof.filterString(null, "hello");
}).hasMessage("value is marked @NonNull but is null");
+ assertEquals(false, dof.filterString("Hello", "Goodbye"));
+ assertEquals(true, dof.filterString("Hello", "Hello"));
+ assertEquals(true, dof.filterString("Hello", null));
+
List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList);
assertEquals(3, latestVersionList.size());
assertEquals("aaaaa", latestVersionList.get(0).getName());
assertEquals("1.0.0", latestVersionList.get(1).getVersion());
assertEquals("name1", latestVersionList.get(2).getName());
assertEquals("0.1.2", latestVersionList.get(2).getVersion());
+
+ latestVersionList.remove(2);
+ latestVersionList.remove(1);
+ List<DummyPfObject> newestVersionList = dof.latestVersionFilter(latestVersionList);
+ assertEquals(latestVersionList, newestVersionList);
}
}
<artifactId>policy-models-tosca</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
package org.onap.policy.models.pdp.concepts;
-import lombok.Getter;
+import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
-import lombok.Setter;
import lombok.ToString;
import org.onap.policy.models.pdp.enums.PdpHealthStatus;
import org.onap.policy.models.pdp.enums.PdpState;
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-@Getter
-@Setter
@ToString
@NoArgsConstructor
+@Data
public class Pdp {
@NonNull
// Regular expression
private String name;
- // Regular Expression, set to LATEST_VERRSION to get the latest version
+ // Regular Expression, set to to get the latest version
private String version;
private PdpState groupState;
// @formatter:off
List<PdpGroup> returnList = originalList.stream()
- .filter(p -> filterOnRegexp(p.getName(), name))
- .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version))
- .filter(p -> ObjectUtils.compare(p.getPdpGroupState(), groupState) == 0)
+ .filter(p -> filterString(p.getName(), name))
+ .filter(p -> (version != null && LATEST_VERSION.equals(version))
+ || filterString(p.getVersion(), version))
+ .filter(p -> groupState == null || ObjectUtils.compare(p.getPdpGroupState(), groupState) == 0)
.filter(p -> filterOnPdpType(p, pdpType))
.filter(p -> filterOnPolicyType(p, policyType))
.filter(p -> filterOnPolicy(p, policy))
import java.util.List;
import java.util.Map;
-import lombok.Getter;
+import lombok.Data;
import lombok.NonNull;
-import lombok.Setter;
-import lombok.ToString;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier;
*
* @author Ram Krishna Verma (ram.krishna.verma@est.tech)
*/
-@Getter
-@Setter
-@ToString
+@Data
public class PdpSubGroup {
private String pdpType;
private List<ToscaPolicyTypeIdentifier> supportedPolicyTypes;
import java.util.Map;
import java.util.Map.Entry;
+import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
private Map<String, String> properties;
// @formatter:off
- @OneToMany
+ @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@CollectionTable(joinColumns = {
@JoinColumn(name = "pdpGroupParentKeyName", referencedColumnName = "parentKeyName"),
@JoinColumn(name = "pdpGroupParentKeyVersion", referencedColumnName = "parentKeyVersion"),
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import javax.persistence.CollectionTable;
+
+import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.common.utils.validation.ParameterValidationUtils;
import org.onap.policy.models.base.PfAuthorative;
@ElementCollection
private Map<String, String> properties;
- // @formatter:ofF
- @OneToMany
- @CollectionTable(
- joinColumns = { @JoinColumn(name = "pdpSubGroupParentKeyName", referencedColumnName = "parentKeyName"),
- @JoinColumn(name = "pdpSubGroupParentKeyVersion", referencedColumnName = "parentKeyVersion"),
- @JoinColumn(name = "pdpSubGroupParentLocalName", referencedColumnName = "parentLocalName"),
- @JoinColumn(name = "pdpSubGroupLocalName", referencedColumnName = "localName") })
+ // @formatter:off
+ @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
+ @JoinTable (
+ joinColumns = {
+ @JoinColumn(name = "pdpParentKeyName", referencedColumnName = "parentKeyName"),
+ @JoinColumn(name = "pdpParentKeyVersion", referencedColumnName = "parentKeyVersion"),
+ @JoinColumn(name = "pdpParentLocalName", referencedColumnName = "parentLocalName"),
+ @JoinColumn(name = "pdpLocalName", referencedColumnName = "localName")
+ }
+ )
// formatter:on
private List<JpaPdp> pdpInstances;
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.resources.ResourceUtils;
+
+/**
+ * Test of the {@link PdpGroupFilter} class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PdpGroupFilterTest {
+ private List<PdpGroup> pdpGroupList;
+
+ /**
+ * Set up a PDP group list for filtering.
+ *
+ * @throws CoderException on JSON decoding errors
+ */
+ @Before
+ public void setupPdpGroupList() throws CoderException {
+ String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsForFiltering.json");
+ PdpGroups pdpGroups = new StandardCoder().decode(originalJson, PdpGroups.class);
+ pdpGroupList = pdpGroups.getGroups();
+ }
+
+ @Test
+ public void testNullList() {
+ PdpGroupFilter filter = PdpGroupFilter.builder().build();
+
+ assertThatThrownBy(() -> {
+ filter.filter(null);
+ }).hasMessage("originalList is marked @NonNull but is null");
+ }
+
+ @Test
+ public void testFilterNothing() {
+ PdpGroupFilter filter = PdpGroupFilter.builder().build();
+
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertTrue(filteredList.containsAll(pdpGroupList));
+ }
+
+ @Test
+ public void testFilterLatestVersion() {
+ PdpGroupFilter filter = PdpGroupFilter.builder().version(PdpGroupFilter.LATEST_VERSION).build();
+
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+ assertEquals("1.2.4", filteredList.get(0).getVersion());
+ assertEquals("1.2.3", filteredList.get(1).getVersion());
+ }
+
+ @Test
+ public void testFilterNameVersion() {
+ PdpGroupFilter filter = PdpGroupFilter.builder().name("PdpGroup0").build();
+ List<PdpGroup> filteredList = filter.filter(pdpGroupList);
+ assertEquals(3, filteredList.size());
+
+ filter = PdpGroupFilter.builder().name("PdpGroup1").build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+
+ filter = PdpGroupFilter.builder().name("PdpGroup2").build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+
+ filter = PdpGroupFilter.builder().version("1.2.3").build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(2, filteredList.size());
+
+ filter = PdpGroupFilter.builder().name("PdpGroup0").version("1.2.3").build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(1, filteredList.size());
+
+ filter = PdpGroupFilter.builder().name("PdpGroup1").version("1.2.9").build();
+ filteredList = filter.filter(pdpGroupList);
+ assertEquals(0, filteredList.size());
+ }
+}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
group.setDescription("B");
assertTrue(hash != group.hashCode());
}
+
+ @Test
+ public void testCompareTo() {
+ PdpGroup pdpGroup0 = new PdpGroup();
+ pdpGroup0.setName("Name0");
+ pdpGroup0.setVersion("1.2.3");
+
+ PdpGroup pdpGroup1 = new PdpGroup();
+ pdpGroup1.setName("Name0");
+ pdpGroup1.setVersion("1.2.3");
+
+ assertEquals(0, pdpGroup0.compareTo(pdpGroup1));
+
+ PdpGroups pdpGroups = new PdpGroups();
+ pdpGroups.setGroups(new ArrayList<>());
+ pdpGroups.getGroups().add(pdpGroup0);
+ pdpGroups.getGroups().add(pdpGroup1);
+
+ List<Map<String, PdpGroup>> mapList = pdpGroups.toMapList();
+
+ assertEquals(1, mapList.size());
+ assertEquals(1, mapList.get(0).size());
+ }
}
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
+import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
import org.onap.policy.models.dao.impl.DefaultPfDao;
+import org.onap.policy.models.pdp.concepts.Pdp;
+import org.onap.policy.models.pdp.concepts.PdpGroup;
import org.onap.policy.models.pdp.concepts.PdpGroups;
-import org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup;
import org.onap.policy.models.pdp.persistence.provider.PdpProvider;
import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
}
@Test
- public void testPoliciesGet() throws Exception {
+ public void testGroupsGet() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().getPdpGroups(null, null, null);
}).hasMessage("dao is marked @NonNull but is null");
}).hasMessage("dao is marked @NonNull but is null");
String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
-
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
}
@Test
- public void testPolicyCreate() throws Exception {
+ public void testGroupsCreate() throws Exception {
assertThatThrownBy(() -> {
new PdpProvider().createPdpGroups(null, null);
}).hasMessage("dao is marked @NonNull but is null");
}).hasMessage("pdpGroups is marked @NonNull but is null");
String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
-
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
PdpGroups createdPdpGroups0 = new PdpGroups();
}
@Test
- public void testPolicyCreateNoPdp() throws Exception {
+ public void testGroupsCreateNoPdp() throws Exception {
String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroupsNoPDPs.json");
PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
String gotJson = standardCoder.encode(gotPdpGroups0);
assertEquals(originalTweakedJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
}
- /*
- * @Test public void testPolicyUpdate() throws Exception { try { new SimpleToscaProvider().updatePolicies(null,
- * null); fail("test should throw an exception here"); } catch (Exception exc) {
- * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); }
- *
- * try { new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate());
- * fail("test should throw an exception here"); } catch (Exception exc) {
- * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); }
- *
- * try { new SimpleToscaProvider().updatePolicies(pfDao, null); fail("test should throw an exception here"); } catch
- * (Exception exc) { assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage()); }
- *
- * ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- * ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
- * ToscaServiceTemplate.class);
- *
- * JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
- * originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- *
- * assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate updatedServiceTemplate = new
- * SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate);
- *
- * assertEquals(originalServiceTemplate, updatedServiceTemplate); }
- *
- * @Test public void testPoliciesDelete() throws Exception { try { new SimpleToscaProvider().deletePolicy(null,
- * null); fail("test should throw an exception here"); } catch (Exception exc) {
- * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); }
- *
- * try { new SimpleToscaProvider().deletePolicy(null, new PfConceptKey());
- * fail("test should throw an exception here"); } catch (Exception exc) {
- * assertEquals("dao is marked @NonNull but is null", exc.getMessage()); }
- *
- * try { new SimpleToscaProvider().deletePolicy(pfDao, null); fail("test should throw an exception here"); } catch
- * (Exception exc) { assertEquals("policyKey is marked @NonNull but is null", exc.getMessage()); }
- *
- * ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- * ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
- * ToscaServiceTemplate.class);
- *
- * JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
- * originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
- *
- * assertNotNull(originalServiceTemplate); JpaToscaServiceTemplate createdServiceTemplate = new
- * SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate);
- *
- * assertEquals(originalServiceTemplate, createdServiceTemplate);
- *
- * PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
- *
- * JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicy(pfDao, new
- * PfConceptKey(policyKey));
- *
- * assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey),
- * deletedServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey));
- *
- * try { new SimpleToscaProvider().getPolicies(pfDao, new PfConceptKey(policyKey));
- * fail("test should throw an exception here"); } catch (Exception exc) {
- * assertEquals("policy not found: onap.restart.tca:1.0.0", exc.getMessage()); } }
- *
- * @Test public void testAssertPoliciesExist() throws PfModelException { JpaToscaServiceTemplate testServiceTemplate
- * = new JpaToscaServiceTemplate();
- *
- * try { new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate);
- * fail("test should throw an exception here"); } catch (Exception exc) {
- * assertEquals("topology template not specified on service template", exc.getMessage()); }
- *
- * testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); try { new
- * SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); fail("test should throw an exception here"); }
- * catch (Exception exc) { assertEquals("no policies specified on topology template of service template",
- * exc.getMessage()); }
- *
- * testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); try { new
- * SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); fail("test should throw an exception here"); }
- * catch (Exception exc) {
- * assertEquals("list of policies specified on topology template of service template is empty", exc.getMessage()); }
- *
- * }
- */
+
+ @Test
+ public void testGroupsUpdate() throws Exception {
+ assertThatThrownBy(() -> {
+ new PdpProvider().updatePdpGroups(null, null);
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new PdpProvider().updatePdpGroups(null, new ArrayList<>());
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new PdpProvider().updatePdpGroups(pfDao, null);
+ }).hasMessage("pdpGroups is marked @NonNull but is null");
+
+ String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
+
+ PdpGroups createdPdpGroups0 = new PdpGroups();
+ createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
+ String createdJson = standardCoder.encode(createdPdpGroups0);
+ assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
+
+ PdpGroups gotPdpGroups0 = new PdpGroups();
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
+
+ String gotJson = standardCoder.encode(gotPdpGroups0);
+ assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
+
+ String updateJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0Update.json");
+ PdpGroups updatePdpGroups0 = standardCoder.decode(updateJson, PdpGroups.class);
+
+ PdpGroups updatedPdpGroups0 = new PdpGroups();
+ updatedPdpGroups0.setGroups(new PdpProvider().updatePdpGroups(pfDao, updatePdpGroups0.getGroups()));
+
+ List<Pdp> beforePdpInstances = updatePdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances();
+ List<Pdp> afterPdpInstances = updatedPdpGroups0.getGroups().get(0).getPdpSubgroups().get(0).getPdpInstances();
+ assertTrue(beforePdpInstances.containsAll(afterPdpInstances));
+ }
+
+ @Test
+ public void testPoliciesDelete() throws Exception {
+ assertThatThrownBy(() -> {
+ new PdpProvider().deletePdpGroup(null, null, null);
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new PdpProvider().deletePdpGroup(null, null, "version");
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> {
+ new PdpProvider().deletePdpGroup(null, "name", "version");
+ }).hasMessage("dao is marked @NonNull but is null");
+
+ String originalJson = ResourceUtils.getResourceAsString("testdata/PdpGroups0.json");
+ PdpGroups pdpGroups0 = standardCoder.decode(originalJson, PdpGroups.class);
+
+ PdpGroups createdPdpGroups0 = new PdpGroups();
+ createdPdpGroups0.setGroups(new PdpProvider().createPdpGroups(pfDao, pdpGroups0.getGroups()));
+ String createdJson = standardCoder.encode(createdPdpGroups0);
+ assertEquals(originalJson.replaceAll("\\s+", ""), createdJson.replaceAll("\\s+", ""));
+
+ PdpGroups gotPdpGroups0 = new PdpGroups();
+ gotPdpGroups0.setGroups(new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3"));
+
+ String gotJson = standardCoder.encode(gotPdpGroups0);
+ assertEquals(originalJson.replaceAll("\\s+", ""), gotJson.replaceAll("\\s+", ""));
+
+ PdpGroup deletedPdpGroup = new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0", "1.2.3");
+
+ assertEquals(createdPdpGroups0.getGroups().get(0), deletedPdpGroup);
+
+ assertEquals(0, new PdpProvider().getPdpGroups(pfDao, "PdpGroup0", "1.2.3").size());
+
+ assertThatThrownBy(() -> {
+ new PdpProvider().deletePdpGroup(pfDao, "PdpGroup0", "1.2.3");
+ }).hasMessage("delete of PDP group \"PdpGroup0:1.2.3\" failed, PDP group does not exist");
+ }
}
--- /dev/null
+{
+ "groups": [
+ {
+ "name": "PdpGroup0",
+ "version": "1.2.3",
+ "description": "group description",
+ "pdpGroupState": "PASSIVE",
+ "properties": {
+ "groupProperty0": "Value of Group Property 0"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "APEX",
+ "supportedPolicyTypes": [
+ {
+ "name": "policy.type.0",
+ "version": "1.2.3"
+ }
+ ],
+ "policies": [
+ {
+ "name": "Policy0",
+ "version": "4.5.6"
+ }
+ ],
+ "currentInstanceCount": 123,
+ "desiredInstanceCount": 456,
+ "properties": {
+ "subgroupProperty0": "Value of sub Group Property 0"
+ },
+ "pdpInstances": [
+ {
+ "instanceId": "apex-0",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ },
+ {
+ "instanceId": "apex-1",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ },
+ {
+ "instanceId": "apex-2",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ }
+ ]
+ },
+ {
+ "pdpType": "Drools",
+ "supportedPolicyTypes": [
+ {
+ "name": "policy.type.1",
+ "version": "4.5.6"
+ }
+ ],
+ "policies": [
+ {
+ "name": "Policy0",
+ "version": "4.5.6"
+ }
+ ],
+ "currentInstanceCount": 123,
+ "desiredInstanceCount": 456,
+ "properties": {
+ "subgroupProperty0": "Value of sub Group Property 0"
+ },
+ "pdpInstances": [
+ {
+ "instanceId": "drools-0",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
--- /dev/null
+{
+ "groups": [
+ {
+ "name": "PdpGroup0",
+ "version": "1.2.3",
+ "description": "group description",
+ "pdpGroupState": "PASSIVE",
+ "properties": {
+ "groupProperty0": "Value of Group Property 0"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "APEX",
+ "supportedPolicyTypes": [
+ {
+ "name": "policy.type.0",
+ "version": "1.2.3"
+ }
+ ],
+ "policies": [
+ {
+ "name": "Policy0",
+ "version": "4.5.6"
+ }
+ ],
+ "currentInstanceCount": 123,
+ "desiredInstanceCount": 456,
+ "properties": {
+ "subgroupProperty0": "Value of sub Group Property 0"
+ },
+ "pdpInstances": [
+ {
+ "instanceId": "apex-0",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "PdpGroup0",
+ "version": "1.2.4",
+ "description": "group description",
+ "pdpGroupState": "PASSIVE",
+ "properties": {
+ "groupProperty0": "Value of Group Property 0"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "APEX",
+ "supportedPolicyTypes": [
+ {
+ "name": "policy.type.0",
+ "version": "1.2.3"
+ }
+ ],
+ "policies": [
+ {
+ "name": "Policy0",
+ "version": "4.5.6"
+ }
+ ],
+ "currentInstanceCount": 123,
+ "desiredInstanceCount": 456,
+ "properties": {
+ "subgroupProperty0": "Value of sub Group Property 0"
+ },
+ "pdpInstances": [
+ {
+ "instanceId": "apex-0",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "PdpGroup0",
+ "version": "1.2.1",
+ "description": "group description",
+ "pdpGroupState": "PASSIVE",
+ "properties": {
+ "groupProperty0": "Value of Group Property 0"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "APEX",
+ "supportedPolicyTypes": [
+ {
+ "name": "policy.type.0",
+ "version": "1.2.3"
+ }
+ ],
+ "policies": [
+ {
+ "name": "Policy0",
+ "version": "4.5.6"
+ }
+ ],
+ "currentInstanceCount": 123,
+ "desiredInstanceCount": 456,
+ "properties": {
+ "subgroupProperty0": "Value of sub Group Property 0"
+ },
+ "pdpInstances": [
+ {
+ "instanceId": "apex-0",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "PdpGroup1",
+ "version": "1.2.1",
+ "description": "group description",
+ "pdpGroupState": "PASSIVE",
+ "properties": {
+ "groupProperty0": "Value of Group Property 0"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "APEX",
+ "supportedPolicyTypes": [
+ {
+ "name": "policy.type.0",
+ "version": "1.2.3"
+ }
+ ],
+ "policies": [
+ {
+ "name": "Policy0",
+ "version": "4.5.6"
+ }
+ ],
+ "currentInstanceCount": 123,
+ "desiredInstanceCount": 456,
+ "properties": {
+ "subgroupProperty0": "Value of sub Group Property 0"
+ },
+ "pdpInstances": [
+ {
+ "instanceId": "apex-0",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "name": "PdpGroup1",
+ "version": "1.2.3",
+ "description": "group description",
+ "pdpGroupState": "PASSIVE",
+ "properties": {
+ "groupProperty0": "Value of Group Property 0"
+ },
+ "pdpSubgroups": [
+ {
+ "pdpType": "APEX",
+ "supportedPolicyTypes": [
+ {
+ "name": "policy.type.0",
+ "version": "1.2.3"
+ }
+ ],
+ "policies": [
+ {
+ "name": "Policy0",
+ "version": "4.5.6"
+ }
+ ],
+ "currentInstanceCount": 123,
+ "desiredInstanceCount": 456,
+ "properties": {
+ "subgroupProperty0": "Value of sub Group Property 0"
+ },
+ "pdpInstances": [
+ {
+ "instanceId": "apex-0",
+ "pdpState": "ACTIVE",
+ "healthy": "NOT_HEALTHY",
+ "message": "message from PDP"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
\ No newline at end of file
// @formatter:off
List<ToscaPolicy> returnList = originalList.stream()
- .filter(p -> filterOnRegexp(p.getName(), name))
- .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version))
- .filter(p -> filterOnRegexp(p.getType(), type))
- .filter(p -> filterOnRegexp(p.getTypeVersion(), typeVersion))
+ .filter(p -> filterString(p.getName(), name))
+ .filter(p -> (version != null && LATEST_VERSION.equals(version))
+ || filterString(p.getVersion(), version))
+ .filter(p -> filterString(p.getType(), type))
+ .filter(p -> filterString(p.getTypeVersion(), typeVersion))
.collect(Collectors.toList());
// @formatter:off
// @formatter:off
List<ToscaPolicyType> returnList = originalList.stream()
- .filter(p -> filterOnRegexp(p.getName(), name))
- .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version))
+ .filter(p -> filterString(p.getName(), name))
+ .filter(p -> (version != null && LATEST_VERSION.equals(version))
+ || filterString(p.getVersion(), version))
.collect(Collectors.toList());
// @formatter:off
*/
public class LegacyOperationalPolicyMapper
implements JpaToscaServiceTemplateMapper<LegacyOperationalPolicy, LegacyOperationalPolicy> {
+
+ // Property name for the operational policy content
+ private static final String CONTENT_PROPERTY = "content";
+
private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapper.class);
private static final PfConceptKey LEGACY_OPERATIONAL_TYPE =
final Map<String, String> propertyMap = new HashMap<>();
toscaPolicy.setProperties(propertyMap);
- toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent());
+ toscaPolicy.getProperties().put(CONTENT_PROPERTY, legacyOperationalPolicy.getContent());
final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0");
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
- final String content = toscaPolicy.getProperties().get("Content");
+ final String content = toscaPolicy.getProperties().get(CONTENT_PROPERTY);
if (toscaPolicy.getProperties() == null) {
String errorMessage = "property \"Content\" not defined on TOSCA policy";
LOGGER.warn(errorMessage);