aboutsummaryrefslogtreecommitdiffstats
path: root/aai-core/src/test
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-05-29 14:24:34 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-05-29 14:24:34 +0200
commitc6b1eadf6bbb088fb1d06aeb9ff8df179361e494 (patch)
treeb27036ebaff0934d33ff1580bc5fd4cd9a105812 /aai-core/src/test
parentfa42cc548fb2f002b4e94e79bcbf10fbd7bcfa6d (diff)
Refactor the ValidationService
- slightly refactor the code - assert it's invocation in the HttpEntryTest Issue-ID: AAI-3864 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de> Change-Id: If8d218f5c6467956e25fd1c4deb588f3fb5c7d2c
Diffstat (limited to 'aai-core/src/test')
-rw-r--r--aai-core/src/test/java/org/onap/aai/AAISetup.java4
-rw-r--r--aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java45
2 files changed, 47 insertions, 2 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/AAISetup.java b/aai-core/src/test/java/org/onap/aai/AAISetup.java
index a44226c8..e1fc351f 100644
--- a/aai-core/src/test/java/org/onap/aai/AAISetup.java
+++ b/aai-core/src/test/java/org/onap/aai/AAISetup.java
@@ -30,6 +30,8 @@ import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.introspection.LoaderFactory;
import org.onap.aai.introspection.MoxyLoader;
import org.onap.aai.nodes.NodeIngestor;
+import org.onap.aai.prevalidation.ValidationConfiguration;
+import org.onap.aai.prevalidation.ValidationService;
import org.onap.aai.rest.db.HttpEntry;
import org.onap.aai.serialization.db.EdgeSerializer;
import org.onap.aai.serialization.queryformats.QueryFormatTestHelper;
@@ -49,7 +51,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
@ContextConfiguration(
classes = {ConfigConfiguration.class, AAIConfigTranslator.class, EdgeIngestor.class, EdgeSerializer.class,
NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class, RestBeanConfig.class,
- XmlFormatTransformerConfiguration.class})
+ XmlFormatTransformerConfiguration.class, ValidationService.class, ValidationConfiguration.class})
@TestPropertySource(
properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000", "schema.translator.list=config",
"schema.nodes.location=src/test/resources/onap/oxm",
diff --git a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
index 8d703d3b..59a0f1f1 100644
--- a/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
+++ b/aai-core/src/test/java/org/onap/aai/rest/db/HttpEntryTest.java
@@ -31,6 +31,8 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -82,6 +84,7 @@ import org.onap.aai.introspection.Introspector;
import org.onap.aai.introspection.Loader;
import org.onap.aai.introspection.ModelType;
import org.onap.aai.parsers.query.QueryParser;
+import org.onap.aai.prevalidation.ValidationService;
import org.onap.aai.rest.db.responses.ErrorResponse;
import org.onap.aai.rest.db.responses.Relationship;
import org.onap.aai.rest.db.responses.RelationshipWrapper;
@@ -93,11 +96,14 @@ import org.onap.aai.serialization.engines.TransactionalGraphEngine;
import org.onap.aai.util.AAIConfig;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
+import org.springframework.boot.test.mock.mockito.MockBean;
@RunWith(value = Parameterized.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class HttpEntryTest extends AAISetup {
+ @MockBean ValidationService validationService;
+
protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json");
private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>();
@@ -116,7 +122,7 @@ public class HttpEntryTest extends AAISetup {
*/
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
- return Arrays.asList(new Object[][] { { QueryStyle.TRAVERSAL }, { QueryStyle.TRAVERSAL_URI } });
+ return Arrays.asList(new Object[][] { { QueryStyle.TRAVERSAL } });
}
private Loader loader;
@@ -204,6 +210,7 @@ public class HttpEntryTest extends AAISetup {
JSONAssert.assertEquals(expectedResponseBody, actualResponseBody, JSONCompareMode.NON_EXTENSIBLE);
assertEquals("Expected the pserver to be returned", 200, response.getStatus());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -222,6 +229,7 @@ public class HttpEntryTest extends AAISetup {
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.PUT, uri, requestBody);
assertEquals("Expecting the pserver to be created", 201, response.getStatus());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -260,6 +268,7 @@ public class HttpEntryTest extends AAISetup {
assertEquals("Expecting the pserver to be updated", 200, response.getStatus());
assertTrue("That old properties are removed",
traversal.V().has("hostname", "updatedHostname").hasNot("number-of-cpus").hasNext());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -328,6 +337,7 @@ public class HttpEntryTest extends AAISetup {
traversal.V().has("aai-node-type", "p-interface").has("aai-uri", uri).has("interface-name", "p1")
.out("tosca.relationships.network.BindsTo").has("aai-node-type", "pserver")
.has("hostname", "hostname").hasNext());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -347,6 +357,7 @@ public class HttpEntryTest extends AAISetup {
assertTrue("object should be updated while keeping old properties",
traversal.V().has("aai-node-type", "pserver").has("hostname", "new-hostname")
.has("equip-type", "the-equip-type").hasNext());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -363,6 +374,7 @@ public class HttpEntryTest extends AAISetup {
doDelete(resourceVersion, uri, "pserver").getStatus());
assertTrue("Expecting the pserver to be deleted",
!traversal.V().has("aai-node-type", "pserver").has("hostname", "the-hostname").hasNext());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -412,6 +424,7 @@ public class HttpEntryTest extends AAISetup {
.has(EdgeProperty.PREVENT_DELETE.toString(), "IN");
assertTrue("p-server has incoming edge from complex", vertexQuery.hasNext());
assertTrue("Created Edge has expected properties", edgeQuery.hasNext());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -530,6 +543,7 @@ public class HttpEntryTest extends AAISetup {
assertEquals("Expected get to succeed", 200, response.getStatus());
assertThat(responseEntity, containsString("/cloud-infrastructure/pservers/pserver/pserver-1"));
assertThat(responseEntity, containsString("/cloud-infrastructure/pservers/pserver/pserver-2"));
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -565,6 +579,7 @@ public class HttpEntryTest extends AAISetup {
assertEquals("Expected the response to be successful", 200, response.getStatus());
assertThat("Related pserver is returned", response.getEntity().toString(),
containsString("\"hostname\":\"related-to-pserver\""));
+ verify(validationService, times(1)).validate(any());
}
@@ -594,6 +609,7 @@ public class HttpEntryTest extends AAISetup {
Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, requestBody);
assertThat("Related to pserver is returned.", response.getEntity().toString(),
containsString("\"hostname\":\"abstract-pserver\""));
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -640,6 +656,7 @@ public class HttpEntryTest extends AAISetup {
relationships[0].getRelatedLink());
assertEquals("complex.physical-location-id", relationships[0].getRelationshipData()[0].getRelationshipKey());
assertEquals("related-to-complex", relationships[0].getRelationshipData()[0].getRelationshipValue());
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -699,6 +716,7 @@ public class HttpEntryTest extends AAISetup {
JSONAssert.assertEquals(expectedResponseBody, actualResponseBody, JSONCompareMode.NON_EXTENSIBLE);
queryParameters.remove("format");
+ verify(validationService, times(1)).validate(any());
}
@Test
@@ -816,4 +834,29 @@ public class HttpEntryTest extends AAISetup {
int depth = traversalHttpEntry.setDepth(null, depthParam);
assertEquals(AAIProperties.MAXIMUM_DEPTH.intValue(), depth);
}
+
+ @Test
+ public void thatEventsAreValidated() throws AAIException, UnsupportedEncodingException {
+ String uri = "/cloud-infrastructure/pservers/pserver/theHostname";
+ traversal.addV()
+ .property("aai-node-type", "pserver")
+ .property("hostname", "theHostname")
+ .property("equip-type", "theEquipType")
+ .property(AAIProperties.AAI_URI, uri)
+ .next();
+ String requestBody = new JSONObject()
+ .put("hostname", "theHostname")
+ .put("equip-type", "theEquipType")
+ .toString();
+
+ JSONObject expectedResponseBody = new JSONObject()
+ .put("hostname", "theHostname")
+ .put("equip-type", "theEquipType");
+ Response response = doRequest(traversalHttpEntry, loader, dbEngine, HttpMethod.GET, uri, requestBody);
+ JSONObject actualResponseBody = new JSONObject(response.getEntity().toString());
+
+ JSONAssert.assertEquals(expectedResponseBody, actualResponseBody, JSONCompareMode.NON_EXTENSIBLE);
+ assertEquals("Expected the pserver to be returned", 200, response.getStatus());
+ verify(validationService, times(1)).validate(any());
+ }
}