summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/crud
diff options
context:
space:
mode:
authorRavi Geda <gravik@amdocs.com>2018-11-28 18:14:33 +0000
committerRavi Geda <gravik@amdocs.com>2018-11-29 09:47:16 +0000
commit9ae8ae65c0aff6b8fd4e94460b44af33cf15aa50 (patch)
treed54422cab7ef90fdd8a66038326550506004419f /src/test/java/org/onap/crud
parent18f7af386802e750ad983ba2cdf4d9b84b4ed5ed (diff)
Upgrade version of aai-common
Update OXM Model Loader and Edge Rules Loader to use the 1810 schema ingestion mechanism. Update tests accordingly. Change-Id: I979951fcdcaf901c508c30d770b83dfa3d52bde4 Issue-ID: AAI-1952 Signed-off-by: Ravi Geda <gravik@amdocs.com>
Diffstat (limited to 'src/test/java/org/onap/crud')
-rw-r--r--src/test/java/org/onap/crud/OXMModelLoaderSetup.java79
-rw-r--r--src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java6
-rw-r--r--src/test/java/org/onap/crud/event/GraphEventTest.java6
-rw-r--r--src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java7
-rw-r--r--src/test/java/org/onap/crud/service/AaiResourceServiceTest.java215
-rw-r--r--src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java6
-rw-r--r--src/test/java/org/onap/crud/service/CrudRestServiceTest.java7
-rw-r--r--src/test/java/org/onap/crud/service/TestResourceServiceEdgeOperations.java284
8 files changed, 105 insertions, 505 deletions
diff --git a/src/test/java/org/onap/crud/OXMModelLoaderSetup.java b/src/test/java/org/onap/crud/OXMModelLoaderSetup.java
new file mode 100644
index 0000000..0b34048
--- /dev/null
+++ b/src/test/java/org/onap/crud/OXMModelLoaderSetup.java
@@ -0,0 +1,79 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.crud;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.aai.edges.EdgeIngestor;
+import org.onap.aai.nodes.NodeIngestor;
+import org.onap.aai.setup.AAIConfigTranslator;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.SchemaVersions;
+import org.onap.schema.EdgePropsConfiguration;
+import org.onap.schema.EdgeRulesLoader;
+import org.onap.schema.OxmModelLoader;
+
+public class OXMModelLoaderSetup {
+
+ private EdgeRulesLoader edgeRulesLoader;
+
+ private OxmModelLoader oxmModelLoader;
+
+ @Mock
+ private SchemaLocationsBean schemaLocationsBean;
+
+ @Mock
+ private SchemaVersions schemaVersions;
+
+ @Mock
+ private EdgePropsConfiguration edgePropsConfiguration;
+
+ private List<SchemaVersion> schemaVersionList = new ArrayList<>();
+
+ @Before
+ public void schemaBeanMockSetup() throws Exception {
+
+ schemaVersionList.add(new SchemaVersion("v8"));
+ schemaVersionList.add(new SchemaVersion("v9"));
+ schemaVersionList.add(new SchemaVersion("v10"));
+ schemaVersionList.add(new SchemaVersion("v11"));
+ schemaVersionList.add(new SchemaVersion("v13"));
+
+ Mockito.when(schemaVersions.getVersions()).thenReturn(schemaVersionList);
+ Mockito.when(schemaLocationsBean.getNodesInclusionPattern()).thenReturn(Arrays.asList(".*oxm(.*).xml"));
+ Mockito.when(schemaLocationsBean.getEdgesInclusionPattern()).thenReturn(Arrays.asList("DbEdgeRules_.*.json"));
+ Mockito.when(schemaLocationsBean.getNodeDirectory()).thenReturn("src/test/resources/multi-oxm/");
+ Mockito.when(schemaLocationsBean.getEdgeDirectory()).thenReturn("src/test/resources/rules");
+ Mockito.when(edgePropsConfiguration.getEdgePropsDir()).thenReturn("src/test/resources/edgeProps/");
+
+ AAIConfigTranslator aaiConfigTranslator = new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
+ NodeIngestor nodeIngestor = new NodeIngestor(aaiConfigTranslator);
+ EdgeIngestor edgeIngestor = new EdgeIngestor(aaiConfigTranslator, schemaVersions);
+ edgeRulesLoader = new EdgeRulesLoader(aaiConfigTranslator, edgeIngestor, edgePropsConfiguration);
+ oxmModelLoader = new OxmModelLoader(aaiConfigTranslator, nodeIngestor);
+ }
+} \ No newline at end of file
diff --git a/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java b/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java
index de56992..0afa0a6 100644
--- a/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java
+++ b/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java
@@ -23,6 +23,9 @@ package org.onap.crud.event;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
import org.onap.crud.entity.Vertex;
import org.onap.crud.event.GraphEvent.GraphEventOperation;
import org.onap.crud.event.envelope.GraphEventEnvelope;
@@ -34,7 +37,8 @@ import org.skyscreamer.jsonassert.comparator.CustomComparator;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
-public class GraphEventEnvelopeTest {
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class GraphEventEnvelopeTest extends OXMModelLoaderSetup {
@Test
public void testPublishedEventFormat() throws Exception {
diff --git a/src/test/java/org/onap/crud/event/GraphEventTest.java b/src/test/java/org/onap/crud/event/GraphEventTest.java
index f9a4c6c..64b5342 100644
--- a/src/test/java/org/onap/crud/event/GraphEventTest.java
+++ b/src/test/java/org/onap/crud/event/GraphEventTest.java
@@ -37,8 +37,12 @@ import org.onap.crud.event.GraphEvent.GraphEventOperation;
import org.onap.crud.event.GraphEvent.GraphEventResult;
import org.onap.crud.event.GraphEventVertex;
import org.onap.crud.exception.CrudException;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
-public class GraphEventTest {
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class GraphEventTest extends OXMModelLoaderSetup{
private final String vertexPayload = "{" +
"\"key\": \"test-uuid\"," +
"\"type\": \"pserver\"," +
diff --git a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
index e5ac52d..a5edd7c 100644
--- a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
+++ b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java
@@ -34,7 +34,12 @@ import org.onap.schema.OxmModelLoader;
import com.google.gson.Gson;
import com.google.gson.JsonParser;
-public class GraphEventResponseHandlerTest {
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
+
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class GraphEventResponseHandlerTest extends OXMModelLoaderSetup {
@Rule
public ExpectedException expectedException = ExpectedException.none();
diff --git a/src/test/java/org/onap/crud/service/AaiResourceServiceTest.java b/src/test/java/org/onap/crud/service/AaiResourceServiceTest.java
deleted file mode 100644
index c23f3ac..0000000
--- a/src/test/java/org/onap/crud/service/AaiResourceServiceTest.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-package org.onap.crud.service;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.Map;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.aai.exceptions.AAIException;
-import org.onap.aai.serialization.db.EdgeProperty;
-import org.onap.aai.serialization.db.EdgeRule;
-import org.onap.aai.serialization.db.EdgeRules;
-import org.onap.aai.serialization.db.EdgeType;
-import org.onap.crud.exception.CrudException;
-import org.onap.crud.parser.EdgePayload;
-import com.google.gson.JsonElement;
-
-public class AaiResourceServiceTest {
-
- public AaiResourceService aaiResSvc = null;
-
-
- @Before
- public void setup() {
- System.setProperty("AJSC_HOME", ".");
- System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
-
- aaiResSvc = new AaiResourceService();
- }
-
-
- /**
- * This test validates that we can apply db edge rules against an edge request
- * payload and have the properties defined in the edge rules merged into the
- * payload.
- *
- * @throws CrudException
- * @throws AAIException
- */
- @Test
- public void applyEdgeRulesToPayloadTest() throws CrudException, AAIException {
-
- String content = "{" +
- "\"source\": \"services/inventory/v8/l-interface/369553424\", " +
- "\"target\": \"services/inventory/v8/logical-link/573444128\"," +
- "\"properties\": {" +
- "}" +
- "}";
-
- // Convert our simulated payload to an EdgePayload object.
- EdgePayload payload = EdgePayload.fromJson(content);
-
- // Now, apply the db edge rules against our edge payload.
- EdgePayload payloadAfterEdgeRules = aaiResSvc.applyEdgeRulesToPayload(payload);
-
- EdgeRules rules = EdgeRules.getInstance();
- EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l-interface", "logical-link");
- Map<EdgeProperty, String> edgeProps = rule.getEdgeProperties();
-
- // Validate that the properties defined in the DB edge rules show up in our
- // final payload.
- for(EdgeProperty key : edgeProps.keySet()) {
- assertTrue(payloadAfterEdgeRules.toString().contains(key.toString()));
- }
- }
-
-
- /**
- * This test validates that trying to apply edge rules where there is no
- * db edge rules entry for the supplied source and target vertex types
- * produces an exception.
- *
- * @throws CrudException
- */
- @Test
- public void noRuleForEdgeTest() throws CrudException {
-
- String content = "{" +
- "\"source\": \"services/inventory/v8/commodore-64/12345\", " +
- "\"target\": \"services/inventory/v8/jumpman/67890\"," +
- "\"properties\": {" +
- "}" +
- "}";
-
- // Convert our simulated payload to an EdgePayload object.
- EdgePayload payload = EdgePayload.fromJson(content);
-
- // Now, apply the db edge rules against our edge payload.
- try {
- aaiResSvc.applyEdgeRulesToPayload(payload);
-
- } catch (CrudException e) {
-
- // We expected an exception since there is no rule for our made up vertices..
- assertTrue(e.getMessage().contains("No edge rules for"));
- return;
- }
-
- // If we're here then something unexpected happened...
- fail();
- }
-
-
- /**
- * This test validates that it is possible to merge client supplied and edge rule
- * supplied properties into one edge property list.
- *
- * @throws Exception
- */
- @Test
- public void mergeEdgePropertiesTest() throws Exception {
-
- String content = "{" +
- "\"source\": \"services/inventory/v8/l-interface/369553424\", " +
- "\"target\": \"services/inventory/v8/logical-link/573444128\"," +
- "\"properties\": {" +
- "\"multiplicity\": \"many\"," +
- "\"is-parent\": true," +
- "\"uses-resource\": \"true\"," +
- "\"has-del-target\": \"true\"" +
- "}" +
- "}";
-
- EdgePayload payload = EdgePayload.fromJson(content);
- EdgeRules rules = EdgeRules.getInstance();
- EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l-interface", "logical-link");
- Map<EdgeProperty, String> edgeProps = rule.getEdgeProperties();
-
- // Merge the client supplied properties with the properties defined in the DB edge rules.
- JsonElement mergedProperties =
- aaiResSvc.mergeProperties(payload.getProperties(), rule.getEdgeProperties());
-
- // Now, validate that the resulting set of properties contains both the client and edge
- // rule supplied properties.
- String mergedPropertiesString = mergedProperties.toString();
- assertTrue("Client supplied property 'multiplicity' is missing from merged properties set",
- mergedPropertiesString.contains("multiplicity"));
- assertTrue("Client supplied property 'is-parent' is missing from merged properties set",
- mergedPropertiesString.contains("is-parent"));
- assertTrue("Client supplied property 'uses-resource' is missing from merged properties set",
- mergedPropertiesString.contains("uses-resource"));
- assertTrue("Client supplied property 'has-del-target' is missing from merged properties set",
- mergedPropertiesString.contains("has-del-target"));
-
- for(EdgeProperty key : edgeProps.keySet()) {
- assertTrue("Edge rule supplied property '" + key.toString() + "' is missing from merged properties set",
- mergedPropertiesString.contains(key.toString()));
- }
- }
-
- /**
- * This test validates that if we try to merge client supplied edge properties
- * with the properties defined in the db edge rules, and there is a conflict,
- * then the merge will fail.
- *
- * @throws Exception
- */
- @Test
- public void mergeEdgePropertiesConflictTest() throws Exception {
-
- String content = "{" +
- "\"source\": \"services/inventory/v8/l-interface/369553424\", " +
- "\"target\": \"services/inventory/v8/logical-link/573444128\"," +
- "\"properties\": {" +
- "\"contains-other-v\": \"OUT\"" +
- "}" +
- "}";
-
- EdgePayload payload = EdgePayload.fromJson(content);
- EdgeRules rules = EdgeRules.getInstance();
- EdgeRule rule = rules.getEdgeRule(EdgeType.COUSIN, "l-interface", "logical-link");
-
- try {
-
- // Try to merge our client supplied properties with the properties defined
- // in the db edge rules.
- aaiResSvc.mergeProperties(payload.getProperties(), rule.getEdgeProperties());
-
- } catch (CrudException e) {
-
- // We should have gotten an exception because we are trying to set a parameter which is
- // already defined in the db edge rules, so if we're here then we are good.
- return;
- }
-
- // If we made it here then we were allowed to set a property that is already defined
- // in the db edge rules, which we should not have...
- fail();
- }
-
-
-
-
-}
diff --git a/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java b/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java
index a7479b5..31a0ede 100644
--- a/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java
+++ b/src/test/java/org/onap/crud/service/ChampDaoExceptionsTest.java
@@ -43,8 +43,12 @@ import org.onap.crud.entity.Edge;
import org.onap.crud.entity.Vertex;
import org.onap.crud.exception.CrudException;
import org.slf4j.MDC;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
-public class ChampDaoExceptionsTest {
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class ChampDaoExceptionsTest extends OXMModelLoaderSetup {
// @formatter:off
private final String champVertex = "{" +
"\"key\": \"test-uuid\"," +
diff --git a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
index bc70a36..c2106ed 100644
--- a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
+++ b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java
@@ -40,9 +40,12 @@ import org.onap.crud.service.util.TestHeaders;
import org.onap.crud.service.util.TestRequest;
import org.onap.crud.service.util.TestUriInfo;
import org.onap.schema.EdgeRulesLoader;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.crud.OXMModelLoaderSetup;
-
-public class CrudRestServiceTest {
+@RunWith(MockitoJUnitRunner.Silent.class)
+public class CrudRestServiceTest extends OXMModelLoaderSetup{
private final String putVertexPayload = "{" +
"\"id\": \"test-uuid\"," +
"\"type\": \"pserver\"," +
diff --git a/src/test/java/org/onap/crud/service/TestResourceServiceEdgeOperations.java b/src/test/java/org/onap/crud/service/TestResourceServiceEdgeOperations.java
deleted file mode 100644
index 4998e74..0000000
--- a/src/test/java/org/onap/crud/service/TestResourceServiceEdgeOperations.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/**
- * ============LICENSE_START=======================================================
- * org.onap.aai
- * ================================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-package org.onap.crud.service;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-import java.security.cert.X509Certificate;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map.Entry;
-import javax.security.auth.x500.X500Principal;
-import javax.ws.rs.core.EntityTag;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MultivaluedHashMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.crud.exception.CrudException;
-import org.onap.crud.util.TestUtil;
-import org.onap.schema.OxmModelLoader;
-import org.springframework.mock.web.MockHttpServletRequest;
-import com.att.aft.dme2.internal.jersey.api.client.ClientResponse.Status;
-
-public class TestResourceServiceEdgeOperations {
-
- private MockHttpServletRequest servletRequest;
- private UriInfo uriInfo;
- private HttpHeaders headers;
- private AbstractGraphDataService graphDataService;
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- System.setProperty("CONFIG_HOME", "src/test/resources");
- System.setProperty("AJSC_HOME", ".");
- System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local");
-
- OxmModelLoader.loadModels();
- }
-
- @Before
- public void setUp() throws Exception {
- graphDataService = mock(CrudGraphDataService.class);
- uriInfo = mock(UriInfo.class);
-
- mockHeaderRequests(getCreateHeaders());
-
- servletRequest = new MockHttpServletRequest();
- servletRequest.setSecure(true);
- servletRequest.setScheme("https");
- servletRequest.setServerPort(9520);
- servletRequest.setServerName("localhost");
- servletRequest.setRequestURI("/services/inventory/relationships/");
-
- setUser("CN=ONAP, OU=ONAP, O=ONAP, L=Ottawa, ST=Ontario, C=CA");
-
- servletRequest.setAttribute("javax.servlet.request.cipher_suite", "");
- }
-
- private MultivaluedHashMap<String, String> getCreateHeaders() {
- MultivaluedHashMap<String, String> headersMap = new MultivaluedHashMap<>();
- headersMap.put("X-TransactionId", createSingletonList("transaction-id"));
- headersMap.put("X-FromAppId", createSingletonList("app-id"));
- headersMap.put("Host", createSingletonList("hostname"));
- return headersMap;
- }
-
- private void mockHeaderRequests(MultivaluedHashMap<String, String> headersMap) {
- headers = Mockito.mock(HttpHeaders.class);
- for (Entry<String, List<String>> entry : headersMap.entrySet()) {
- when(headers.getRequestHeader(entry.getKey())).thenReturn(entry.getValue());
- }
- when(headers.getRequestHeaders()).thenReturn(headersMap);
- }
-
- @Test
- public void testCreateRelationship() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-auto-props.json");
-
- Response response = callCreateRelationship(postEdgeBody);
-
- assertThat(response.getStatus()).isEqualTo(Status.CREATED.getStatusCode());
- }
-
- @Test
- public void testCreateRelationshipWithMatchingType() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-auto-props.json");
- String type = "tosca.relationships.HostedOn";
-
- Response response = createRelationshipWithType(postEdgeBody, type);
-
- assertThat(response.getStatus()).isEqualTo(Status.CREATED.getStatusCode());
- }
-
- @Test
- public void testCreateRelationshipNoMatchingType() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-auto-props.json");
- String type = "type.does.not.match";
-
- Response response = createRelationshipWithType(postEdgeBody, type);
-
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testCreateRelationshipWithTypeNullPropsIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-null-props.json");
- String type = "tosca.relationships.HostedOn";
-
- Response response = createRelationshipWithType(postEdgeBody, type);
-
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testCreateRelationshipWithTypeWithIdIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-with-id.json");
- String type = "tosca.relationships.HostedOn";
-
- Response response = createRelationshipWithType(postEdgeBody, type);
-
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testInvalidUser() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-auto-props.json");
-
- setUser("CN=INVALID, OU=INVALID, O=INVALID, L=Ottawa, ST=Ontario, C=CA");
-
- Response response = callCreateRelationship(postEdgeBody);
-
- assertThat(response.getStatus()).isEqualTo(Status.FORBIDDEN.getStatusCode());
- }
-
- @Test
- public void testNullPropertiesIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-null-props.json");
-
- Response response = callCreateRelationship(postEdgeBody);
-
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testNoPropertiesIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-no-props.json");
-
- Response response = callCreateRelationship(postEdgeBody);
-
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testCreateWithIdIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-with-id.json");
-
- Response response = callCreateRelationship(postEdgeBody);
-
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testNoTypeIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-no-type.json");
-
- Response response = callCreateRelationship(postEdgeBody);
-
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testPatchEdge() throws Exception {
- MultivaluedHashMap<String, String> headersMap = getCreateHeaders();
- headersMap.put(AaiResourceService.HTTP_PATCH_METHOD_OVERRIDE, createSingletonList("PATCH"));
- mockHeaderRequests(headersMap);
-
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-upsert.json");
- String type = "tosca.relationships.HostedOn";
- String id = "12345";
- EntityTag entityTag = new EntityTag("1234");
-
- when(graphDataService.patchEdge(any(), any(), any(), any())).thenReturn(new ImmutablePair<EntityTag, String>(entityTag, "dummy output"));
- AaiResourceService aaiResourceService = new AaiResourceService(graphDataService);
- Response response =
- aaiResourceService.upsertEdge(postEdgeBody, type, id, "uri", headers, uriInfo, servletRequest);
- assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
- }
-
- @Test
- public void testUpdateEdge() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-upsert.json");
- String type = "tosca.relationships.HostedOn";
- String id = "12345";
- EntityTag entityTag = new EntityTag("1234");
-
- when(graphDataService.updateEdge(any(), any(), any(), any())).thenReturn(new ImmutablePair<EntityTag, String>(entityTag, "dummy output"));
- AaiResourceService aaiResourceService = new AaiResourceService(graphDataService);
- Response response =
- aaiResourceService.upsertEdge(postEdgeBody, type, id, "uri", headers, uriInfo, servletRequest);
- assertThat(response.getStatus()).isEqualTo(Status.OK.getStatusCode());
- }
-
- @Test
- public void testUpdateEdgeNullPropsIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-null-props.json");
- String type = "tosca.relationships.HostedOn";
- String id = "12345";
- EntityTag entityTag = new EntityTag("1234");
-
- when(graphDataService.updateEdge(any(), any(), any(), any())).thenReturn(new ImmutablePair<EntityTag, String>(entityTag, "dummy output"));
- AaiResourceService aaiResourceService = new AaiResourceService(graphDataService);
- Response response =
- aaiResourceService.upsertEdge(postEdgeBody, type, id, "uri", headers, uriInfo, servletRequest);
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- @Test
- public void testUpdateEdgeWithMismatchIdIsBadRequest() throws Exception {
- String postEdgeBody = TestUtil.getFileAsString("aai-resource-service/post-edge-upsert.json");
- String type = "tosca.relationships.HostedOn";
- String id = "mismatch";
- EntityTag entityTag = new EntityTag("1234");
-
- when(graphDataService.updateEdge(any(), any(), any(), any())).thenReturn(new ImmutablePair<EntityTag, String>(entityTag, "dummy output"));
- AaiResourceService aaiResourceService = new AaiResourceService(graphDataService);
- Response response =
- aaiResourceService.upsertEdge(postEdgeBody, type, id, "uri", headers, uriInfo, servletRequest);
- assertThat(response.getStatus()).isEqualTo(Status.BAD_REQUEST.getStatusCode());
- }
-
- private Response createRelationshipWithType(String postEdgeBody, String type) throws CrudException, Exception {
- EntityTag entityTag = new EntityTag("1234");
-
- when(graphDataService.addEdge(any(), any(), any())).thenReturn(new ImmutablePair<EntityTag, String>(entityTag, "dummy output"));
- AaiResourceService aaiResourceService = new AaiResourceService(graphDataService);
- Response response =
- aaiResourceService.createRelationship(postEdgeBody, type, "uri", headers, uriInfo, servletRequest);
- return response;
- }
-
- private Response callCreateRelationship(String postEdgeBody) throws CrudException, Exception {
- EntityTag entityTag = new EntityTag("1234");
-
- when(graphDataService.addEdge(any(), any(), any())).thenReturn(new ImmutablePair<EntityTag, String>(entityTag, "dummy output"));
- AaiResourceService aaiResourceService = new AaiResourceService(graphDataService);
- Response response =
- aaiResourceService.createRelationship(postEdgeBody, "uri", headers, uriInfo, servletRequest);
- return response;
- }
-
- private void setUser(String user) {
- X509Certificate mockCertificate = Mockito.mock(X509Certificate.class);
- when(mockCertificate.getSubjectX500Principal()).thenReturn(new X500Principal(user));
- servletRequest.setAttribute("javax.servlet.request.X509Certificate", new X509Certificate[] {mockCertificate});
- }
-
- private List<String> createSingletonList(String listItem) {
- return Collections.<String>singletonList(listItem);
- }
-}