Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / client / aai / entities / uri / ServiceInstanceUriTest.java
index c369767..e829666 100644 (file)
@@ -32,17 +32,14 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.when;
-
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.util.Optional;
-
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.core.UriBuilder;
-
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -59,149 +56,175 @@ import org.onap.so.client.defaultproperties.DefaultAAIPropertiesImpl;
 import org.onap.so.client.graphinventory.exceptions.GraphInventoryPayloadException;
 import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriComputationException;
 import org.onap.so.client.graphinventory.exceptions.GraphInventoryUriNotFoundException;
-
 import com.github.tomakehurst.wiremock.junit.WireMockRule;
 
 @RunWith(MockitoJUnitRunner.class)
 public class ServiceInstanceUriTest {
 
-       private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
-       
-       @Rule
-       public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
-       
-       @Rule
-       public final ExpectedException exception = ExpectedException.none();
-        
-       @Spy
-       public AAIClient client;
-       
-       @InjectMocks
-       public AAIResourcesClient aaiClient = new AAIResourcesClient();
-       
-       @Before
-       public void beforeTest() {
-               doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
-       }
-       @Test
-       public void found() throws IOException {
-               final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
-                
-               ServiceInstanceUri instance = new ServiceInstanceUri("key3");
-               final Optional<String> result = instance.extractRelatedLink(content);
-               final String expected = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
-               assertEquals("result is equal", expected, result.get());
-               
-       }
-       
-       @Test
-       public void oneKey() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-                
-               ServiceInstanceUri instance = new ServiceInstanceUri("key1");
-               ServiceInstanceUri spy = spy(instance);
-               doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getObjectById(any(Object.class));
-               
-               final URI result = spy.build();
-               final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build();
-               assertEquals("result is equal", expected, result);
-               
-       }
-       
-       @Test
-       public void oneKeyQueryParams() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-                
-               ServiceInstanceUri instance = new ServiceInstanceUri("key1");
-               ServiceInstanceUri spy = spy(instance);
-               doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").when(spy).getObjectById(any(Object.class));
-               
-               final URI result = spy.resourceVersion("1234").build();
-               final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build();
-               assertEquals("result is equal", expected, result);
-               
-       }
-       
-       @Test
-       public void oneKeyEncoded() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-                
-               ServiceInstanceUri instance = new ServiceInstanceUri("key1");
-               ServiceInstanceUri spy = spy(instance);
-               doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").when(spy).getObjectById(any(Object.class));
-               
-               final URI result = spy.build();
-               final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space").build();
-               assertEquals("result is equal", expected, result);
-               
-       }
-       
-       @Test
-       public void oneKeyGetKeys() throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-                
-               ServiceInstanceUri instance = new ServiceInstanceUri("key1");
-               ServiceInstanceUri spy = spy(instance);
-               doReturn("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space").when(spy).getObjectById(any(Object.class));
-               
-               assertThat(spy.getURIKeys().values(), contains("key1", "key2", "key3(space"));
-               
-       }
-       @Test
-       public void oneKeyClone() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-               ServiceInstanceUri instance = new ServiceInstanceUri("key1");
-               ServiceInstanceUri spy = spy(instance);
-               String uri = "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
-               doReturn(uri).when(spy).getObjectById(any(Object.class));
-               doReturn(Optional.of(uri)).when(spy).getCachedValue();
-               final URI result = spy.resourceVersion("1234").clone().build();
-               final URI expected = UriBuilder.fromUri("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234").build();
-               assertEquals("result is equal", expected, result);
-       }
-       
-       @Test
-       public void threeKey() throws IOException {
-                
-               ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
-               final URI result = instance.build();
-               final URI expected = UriBuilder.fromPath("/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3").build();
-               assertEquals("result is equal", expected, result);
-               
-       }
-       
-       @Test
-       public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-               final String content = new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json")));
-                
-               ServiceInstanceUri instance = new ServiceInstanceUri("key3");
-               ServiceInstanceUri spy = spy(instance);
-               AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
-               AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
-               when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class), ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
-               when(wrapper.getJson()).thenReturn(content);
-               when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
-               exception.expect(GraphInventoryUriComputationException.class);
-               spy.build();
-               
-       }
-       
-       @Test
-       public void cloneTest() {
-               ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
-               final URI result = instance.build();
-               final URI result2 = instance.clone().queryParam("something", "new").build();
-               assertEquals("uris are not equal", false, result.toString().equals(result2.toString()));
-               
-       }
-       
-       @Test
-       public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
-               ServiceInstanceUri instance = new ServiceInstanceUri("key3");
-               ServiceInstanceUri spy = spy(instance);
-               AAIResourcesClient client = aaiClient;
-               doReturn(client).when(spy).getResourcesClient();
-               wireMockRule.stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3")) 
-                               .willReturn(aResponse() 
-                                       .withStatus(404) 
-                                       .withHeader("Content-Type", "application/json") 
-                                       .withBodyFile("")));
-               exception.expect(NotFoundException.class);
-               spy.build();    
-       }
+    private final static String AAI_JSON_FILE_LOCATION = "src/test/resources/__files/aai/resources/";
+
+    @Rule
+    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
+
+    @Rule
+    public final ExpectedException exception = ExpectedException.none();
+
+    @Spy
+    public AAIClient client;
+
+    @InjectMocks
+    public AAIResourcesClient aaiClient = new AAIResourcesClient();
+
+    @Before
+    public void beforeTest() {
+        doReturn(new DefaultAAIPropertiesImpl(wireMockRule.port())).when(client).getRestProperties();
+    }
+
+    @Test
+    public void found() throws IOException {
+        final String content = new String(
+                Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "service-instance-pathed-query.json")));
+
+        ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+        final Optional<String> result = instance.extractRelatedLink(content);
+        final String expected =
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+        assertEquals("result is equal", expected, result.get());
+
+    }
+
+    @Test
+    public void oneKey()
+            throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+        ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+        ServiceInstanceUri spy = spy(instance);
+        doReturn(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+                        .when(spy).getObjectById(any(Object.class));
+
+        final URI result = spy.build();
+        final URI expected = UriBuilder.fromPath(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+                .build();
+        assertEquals("result is equal", expected, result);
+
+    }
+
+    @Test
+    public void oneKeyQueryParams()
+            throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+        ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+        ServiceInstanceUri spy = spy(instance);
+        doReturn(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+                        .when(spy).getObjectById(any(Object.class));
+
+        final URI result = spy.resourceVersion("1234").build();
+        final URI expected = UriBuilder.fromUri(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234")
+                .build();
+        assertEquals("result is equal", expected, result);
+
+    }
+
+    @Test
+    public void oneKeyEncoded()
+            throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+        ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+        ServiceInstanceUri spy = spy(instance);
+        doReturn(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space")
+                        .when(spy).getObjectById(any(Object.class));
+
+        final URI result = spy.build();
+        final URI expected = UriBuilder.fromUri(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%20space")
+                .build();
+        assertEquals("result is equal", expected, result);
+
+    }
+
+    @Test
+    public void oneKeyGetKeys()
+            throws IOException, URISyntaxException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+
+        ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+        ServiceInstanceUri spy = spy(instance);
+        doReturn(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3%28space")
+                        .when(spy).getObjectById(any(Object.class));
+
+        assertThat(spy.getURIKeys().values(), contains("key1", "key2", "key3(space"));
+
+    }
+
+    @Test
+    public void oneKeyClone() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+        ServiceInstanceUri instance = new ServiceInstanceUri("key1");
+        ServiceInstanceUri spy = spy(instance);
+        String uri =
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3";
+        doReturn(uri).when(spy).getObjectById(any(Object.class));
+        doReturn(Optional.of(uri)).when(spy).getCachedValue();
+        final URI result = spy.resourceVersion("1234").clone().build();
+        final URI expected = UriBuilder.fromUri(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3?resource-version=1234")
+                .build();
+        assertEquals("result is equal", expected, result);
+    }
+
+    @Test
+    public void threeKey() throws IOException {
+
+        ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
+        final URI result = instance.build();
+        final URI expected = UriBuilder.fromPath(
+                "/business/customers/customer/key1/service-subscriptions/service-subscription/key2/service-instances/service-instance/key3")
+                .build();
+        assertEquals("result is equal", expected, result);
+
+    }
+
+    @Test
+    public void notfound() throws IOException, GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+        final String content =
+                new String(Files.readAllBytes(Paths.get(AAI_JSON_FILE_LOCATION + "empty-query-result.json")));
+
+        ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+        ServiceInstanceUri spy = spy(instance);
+        AAIResourcesClient mockResourcesClient = mock(AAIResourcesClient.class);
+        AAIResultWrapper wrapper = mock(AAIResultWrapper.class);
+        when(mockResourcesClient.get(ArgumentMatchers.<AAIResourceUri>any(AAIResourceUri.class),
+                ArgumentMatchers.<Class<NotFoundException>>any())).thenReturn(wrapper);
+        when(wrapper.getJson()).thenReturn(content);
+        when(spy.getResourcesClient()).thenReturn(mockResourcesClient);
+        exception.expect(GraphInventoryUriComputationException.class);
+        spy.build();
+
+    }
+
+    @Test
+    public void cloneTest() {
+        ServiceInstanceUri instance = new ServiceInstanceUri("key1", "key2", "key3");
+        final URI result = instance.build();
+        final URI result2 = instance.clone().queryParam("something", "new").build();
+        assertEquals("uris are not equal", false, result.toString().equals(result2.toString()));
+
+    }
+
+    @Test
+    public void noVertexFound() throws GraphInventoryUriNotFoundException, GraphInventoryPayloadException {
+        ServiceInstanceUri instance = new ServiceInstanceUri("key3");
+        ServiceInstanceUri spy = spy(instance);
+        AAIResourcesClient client = aaiClient;
+        doReturn(client).when(spy).getResourcesClient();
+        wireMockRule
+                .stubFor(get(urlPathMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/key3")).willReturn(
+                        aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBodyFile("")));
+        exception.expect(NotFoundException.class);
+        spy.build();
+    }
 }