From 76a500eff0629b105fd276194c5dd093e0f60d9d Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Tue, 6 Aug 2019 16:15:02 +0000 Subject: Adding basic support for sdnc sim Change-Id: I84ff3c7c22642d41f77cc2ce789b1cc711da9729 Issue-ID: SO-1950 Signed-off-by: waqas.ikram --- .../controller/OperationsControllerTest.java | 25 ++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test') diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java index 36e12089..bcfff95e 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java @@ -26,6 +26,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.Base64; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,6 +35,7 @@ import org.onap.so.sdncsimulator.models.InputRequest; import org.onap.so.sdncsimulator.models.OutputRequest; import org.onap.so.sdncsimulator.providers.ServiceOperationsCacheServiceProvider; import org.onap.so.sdncsimulator.utils.Constants; +import org.onap.so.simulator.model.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; @@ -66,6 +68,8 @@ public class OperationsControllerTest { private static final String SERVICE_TOPOLOGY_OPERATION_URL = "/GENERIC-RESOURCE-API:service-topology-operation/"; + private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + @LocalServerPort private int port; @@ -75,6 +79,10 @@ public class OperationsControllerTest { @Autowired private ServiceOperationsCacheServiceProvider cacheServiceProvider; + @Autowired + private UserCredentials userCredentials; + + @Test public void test_postServiceOperationInformation_successfullyAddedToCache() throws Exception { @@ -127,9 +135,7 @@ public class OperationsControllerTest { } private HttpHeaders getHttpHeaders() { - final HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.setContentType(MediaType.APPLICATION_JSON); - return requestHeaders; + return getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } @@ -149,10 +155,21 @@ public class OperationsControllerTest { return new String(Files.readAllBytes(path)); } - private static File getFile(final String file) throws IOException { + private File getFile(final String file) throws IOException { return new ClassPathResource(file).getFile(); } + private HttpHeaders getHttpHeaders(final String username) { + final HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.add("Authorization", getBasicAuth(username)); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + return requestHeaders; + } + + private String getBasicAuth(final String username) { + return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + } + @After public void after() { cacheServiceProvider.clearAll(); -- cgit 1.2.3-korg