diff --git a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ERemoteTests.java b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ERemoteTests.java index 87630553..18e39772 100644 --- a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ERemoteTests.java +++ b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ERemoteTests.java @@ -8,23 +8,32 @@ */ package com.adobe.campaign.tests.bridge.service; +import com.adobe.campaign.tests.bridge.service.exceptions.AmbiguousMethodException; +import com.adobe.campaign.tests.bridge.service.exceptions.NonExistentJavaObjectException; +import com.adobe.campaign.tests.bridge.service.exceptions.TargetJavaMethodCallException; +import com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import org.hamcrest.Matchers; import org.testng.annotations.Test; +import java.util.HashMap; +import java.util.Map; import java.util.Properties; +import java.util.Random; import static io.restassured.RestAssured.given; //@Test(groups = "E2ERemote") public class E2ERemoteTests { - public static final String EndPointURL = "http://localhost:8080/"; + //public static final String EndPointURL = "http://localhost:8080/"; + public static final String EndPointURL = "https://acc-simulators-ibs-dev.rd.campaign.adobe.com/"; public void testMainHelloWorld() { - given().when().get(EndPointURL + "test").then().assertThat().body(Matchers.startsWith("All systems up")); + given().when().get(EndPointURL + "test").then().assertThat() + .body("overALLSystemState", Matchers.equalTo(IntegroAPI.SYSTEM_UP_MESSAGE)); } - public void testMainHelloWorld_negative() { given().when().get(EndPointURL + "hello").then().assertThat().statusCode(404); } @@ -40,39 +49,57 @@ public void testMainHelloWorldCall() { given().body(l_call).post(EndPointURL + "call").then().assertThat().body("returnValues.call1PL", Matchers.containsInAnyOrder("AT", "AU", "CA", "CH", "DE", "US", "FR", "CN", "IN", "JP", "RU", "BR", - "ID", "GB","MX")); + "ID", "GB", "MX")); } public void testErrors() { JavaCallResults jcr = new JavaCallResults(); - given().body(jcr).post(EndPointURL + "call").then().statusCode(400).and().assertThat() - .body(Matchers.startsWith(IntegroAPI.ERROR_JSON_TRANSFORMATION)); + given().body(jcr).post(EndPointURL + "call").then().statusCode(404).and().assertThat() + .body("title", Matchers.equalTo(IntegroAPI.ERROR_JSON_TRANSFORMATION)) + .body("detail", Matchers.startsWith( + "Unrecognized field \"callDurations\" (class com.adobe.campaign.tests.bridge.service.JavaCalls), not marked as ignorable")) + .body("code", Matchers.equalTo(404)) + .body("bridgeServiceException", Matchers.equalTo(UnrecognizedPropertyException.class.getTypeName())) + .body("originalException", Matchers.equalTo(ErrorObject.STD_NOT_APPLICABLE)); } - public void testTestAccess() { - JavaCallResults jcr = new JavaCallResults(); + public void testCheckConnectivity() { + + Map urlsMap = new HashMap<>(); + urlsMap.put("url1", "not really a url"); + urlsMap.put("url2", "localhost:" + 8080); + + given().body(urlsMap).post(EndPointURL + "service-check").then().assertThat().statusCode(200) + .body("url1", Matchers.equalTo(false), "url2", Matchers.equalTo(true)); - given().body(jcr).post(EndPointURL + "call").then().statusCode(400).and().assertThat() - .body(Matchers.startsWith(IntegroAPI.ERROR_JSON_TRANSFORMATION)); } /** * Testing that we provide the correct error messages whenever the target method throws an error */ - public void testMainEror_Case1InvocationError() { + public void testMainError_Case1InvocationError() { JavaCalls l_call = new JavaCalls(); CallContent myContent = new CallContent(); - myContent.setClassName("com.adobe.campaign.tests.integro.tools.RandomManager"); - myContent.setMethodName("getRandomNumber"); + myContent.setClassName(SimpleStaticMethods.class.getTypeName()); + final String l_calledMethod = "methodThrowingException"; + myContent.setMethodName(l_calledMethod); myContent.setReturnType("java.lang.String"); myContent.setArgs( - new Object[] { 3, 3 }); + new Object[] { 7, 7 }); l_call.getCallContent().put("call1PL", myContent); - given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(400).body( - Matchers.containsString("Minimum number must be strictly inferior than maximum number.")); + given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(500) + .contentType(IntegroAPI.ERROR_CONTENT_TYPE) + .body("title", Matchers.equalTo(IntegroAPI.ERROR_CALLING_JAVA_METHOD)) + .body("detail", Matchers.containsString( + "We do not allow numbers that are equal.")) + .body("code", Matchers.equalTo(500)) + .body("bridgeServiceException", Matchers.equalTo(TargetJavaMethodCallException.class.getTypeName())) + .body("originalException", Matchers.equalTo(IllegalArgumentException.class.getTypeName())) + .body("stackTrace[0]", + Matchers.startsWith(SimpleStaticMethods.class.getTypeName() + "." + l_calledMethod)); } @@ -83,18 +110,22 @@ public void testMainEror_Case2AmbiguousMethodException() { JavaCalls l_call = new JavaCalls(); CallContent myContent = new CallContent(); - myContent.setClassName("com.adobe.campaign.tests.integro.tools.RandomManager"); - myContent.setMethodName("fetchRandomFileName"); + myContent.setClassName("com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods"); + myContent.setMethodName("overLoadedMethod1Arg"); myContent.setReturnType("java.lang.String"); myContent.setArgs( new Object[] { "plop" }); l_call.getCallContent().put("call1PL", myContent); - given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(400).body( - Matchers.containsString(IntegroAPI.ERROR_JSON_TRANSFORMATION)); + given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(404) + .body("title", Matchers.equalTo(IntegroAPI.ERROR_AMBIGUOUS_METHOD)) + .body("detail", Matchers.containsString( + "We could not find a unique method for")) + .body("code", Matchers.equalTo(404)) + .body("bridgeServiceException", Matchers.equalTo(AmbiguousMethodException.class.getTypeName())) + .body("originalException", Matchers.equalTo(ErrorObject.STD_NOT_APPLICABLE)); } - /** * Testing that we provide the correct error messages whenever the target method throws an error */ @@ -102,13 +133,18 @@ public void testMainEror_Case4A_NonExistantJavaException() { JavaCalls l_call = new JavaCalls(); CallContent myContent = new CallContent(); - myContent.setClassName("com.adobe.campaign.tests.integro.tools.NonExistingRandomManager"); - myContent.setMethodName("getRandomNumber"); + myContent.setClassName("com.adobe.campaign.tests.bridgeservice.testdata.SimpleStaticMethodsNonExisting"); + myContent.setMethodName("methodReturningString"); myContent.setReturnType("java.lang.String"); l_call.getCallContent().put("call1PL", myContent); - given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(400).body( - Matchers.containsString(IntegroAPI.ERROR_JAVA_OBJECT_NOT_FOUND)); + given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(404) + .body("title", Matchers.equalTo(IntegroAPI.ERROR_JAVA_OBJECT_NOT_FOUND)) + .body("detail", Matchers.containsString( + "The given class com.adobe.campaign.tests.bridgeservice.testdata.SimpleStaticMethodsNonExisting could not be found.")) + .body("code", Matchers.equalTo(404)) + .body("bridgeServiceException", Matchers.equalTo(NonExistentJavaObjectException.class.getTypeName())) + .body("originalException", Matchers.equalTo(ErrorObject.STD_NOT_APPLICABLE)); } /** @@ -118,27 +154,27 @@ public void testMainEror_Case4B_NonExistantJavaException() { JavaCalls l_call = new JavaCalls(); CallContent myContent = new CallContent(); - myContent.setClassName("com.adobe.campaign.tests.integro.tools.RandomManager"); - myContent.setMethodName("getRandomNumberNonExisting"); + myContent.setClassName("com.adobe.campaign.tests.bridgeservice.testdata.SimpleStaticMethods"); + myContent.setMethodName("methodReturningStringNonExisting"); myContent.setReturnType("java.lang.String"); l_call.getCallContent().put("call1PL", myContent); - given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(400).body( - Matchers.containsString(IntegroAPI.ERROR_JAVA_OBJECT_NOT_FOUND)); + given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(404) + .body("bridgeServiceException", Matchers.equalTo(NonExistentJavaObjectException.class.getTypeName())); } /** * Testing that we provide the correct error messages whenever the target method throws an error */ public void testMainEror_passiingNull() throws JsonProcessingException { - ConfigValueHandlerIBS.ENVIRONMENT_VARS_SETTER_CLASS.activate("a.b.c.NonExistingClass"); + //ConfigValueHandlerIBS.ENVIRONMENT_VARS_SETTER_CLASS.activate("a.b.c.NonExistingClass"); String l_jsonString = "{\n" + " \"callContent\": {\n" + " \"call1\": {\n" - + " \"class\": \"com.adobe.campaign.tests.integro.tools.RandomManager\",\n" - + " \"method\": \"getRandomEmail\",\n" + + " \"class\": \"com.adobe.campaign.tests.bridgeservice.testdata2.StaticMethodsIntegrity\",\n" + + " \"method\": \"assembleBySystemValues\",\n" + " \"returnType\": \"java.lang.String\",\n" + " \"args\": []\n" + " }\n" @@ -149,9 +185,8 @@ public void testMainEror_passiingNull() throws JsonProcessingException { + " }\n" + "}"; - - given().body(l_jsonString).post(EndPointURL + "call").then().assertThat().statusCode(400).body( - Matchers.containsString(IntegroAPI.ERROR_JSON_TRANSFORMATION)); + given().body(l_jsonString).post(EndPointURL + "call").then().assertThat().statusCode(404) + .body("title", Matchers.equalTo(IntegroAPI.ERROR_JSON_TRANSFORMATION)); } @@ -247,7 +282,7 @@ public void testEnvironmentVars() { CallContent l_cc = new CallContent(); l_cc.setClassName("com.adobe.campaign.tests.integro.core.SystemValueHandler"); l_cc.setMethodName("fetchExecutionProperty"); - l_cc.setArgs(new Object[]{"ABC"}); + l_cc.setArgs(new Object[] { "ABC" }); Properties l_authentication = new Properties(); l_authentication.put("ABC", 123); @@ -259,4 +294,52 @@ public void testEnvironmentVars() { body("returnValues.call1PL", Matchers.equalTo("123")); } + //@Test + public void campaignTest() { + //Call 1 + JavaCalls l_myJavaCalls = new JavaCalls(); + + CallContent l_cc = new CallContent(); + l_cc.setClassName("utils.CampaignUtils"); + l_cc.setMethodName("setCurrentAuthenticationToLocalSession"); + l_cc.setArgs(new Object[] { "https://accintg-dev134.rd.campaign.adobe.com/nl/jsp/soaprouter.jsp", + "___e6b37c15-dad1-4d14-8752-c253f91316b5", + "@JeSsPAdsjmjXiPy1_tAS-a1_8Yu9LTm2Dq3saDWRCrYDzveLUDU5vAt3fV2WAyrR4FbQ3UjBRbdjDvv3nelC0byLEWCDxaH7g8A7Ttth0JTlHNS4f877FwlxituJzNTP", + "9576", + "8.6" }); + + Random n = new Random(); + int y = n.nextInt(5000); + + CallContent l_cc2 = new CallContent(); + l_cc2.setClassName("testhelper.NmsRecipientHelper"); + l_cc2.setMethodName("createSimpleRecipient"); + l_cc2.setArgs(new Object[] { "https://accintg-dev134.rd.campaign.adobe.com/nl/jsp/soaprouter.jsp", + "f" + y, "l" + y, "e" + y + "@adobe.com" }); + + Properties l_authentication = new Properties(); + l_authentication.put("ABC", 123); + l_authentication.put("AC.UITEST.MAILING.PORT", "143"); + l_authentication.put("AC.UITEST.MAILING.PREFIX", "testqa"); + l_authentication.put("AC.UITEST.MAILING.PWD", "changeme"); + l_authentication.put("AC.UITEST.MAILING.PROVIDER", "imap"); + l_authentication.put("AC.UITEST.MAILING.FOLDER", "INBOX"); + l_authentication.put("AC.TEST.IMS.USER.TOKEN.ENABLED", "false"); + l_authentication.put("AC.UITEST.LANGUAGE", "en_US"); + l_authentication.put("AC.UITEST.MAILING.HOST", "acc-simulators.email.corp.adobe.com"); + l_authentication.put("AC.UITEST.MAILING.ID", "testqa@acc-simulators.email.corp.adobe.com"); + l_authentication.put("AC.UITEST.SIMULATORS.PUSH.IOS", "http://acc-simulators.dev.corp.adobe.com:443/"); + l_authentication.put("AC.UITEST.SIMULATORS.PUSH.ANDROID", + "https://push-simulator.corp.ethos11-stage-va7.ethos.adobe.net/"); + l_myJavaCalls.setEnvironmentVariables(l_authentication); + + l_myJavaCalls.getCallContent().put("connect", l_cc); + + l_myJavaCalls.getCallContent().put("createProfile", l_cc2); + + given().body(l_myJavaCalls).post(EndPointURL + "call").then().assertThat().statusCode(200). + body("$", Matchers.hasKey("returnValues.createProfile")); + // body("returnValues.createProfile", Matchers.equalTo("123")); + } + } diff --git a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java index 3445ea79..f5b58cf0 100644 --- a/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java +++ b/integroBridgeService/src/test/java/com/adobe/campaign/tests/bridge/service/E2ETests.java @@ -30,8 +30,8 @@ public class E2ETests { public static final String EndPointURL = "http://localhost:8080/"; - private static final int port1 = 1111; protected static final boolean AUTOMATIC_FLAG = false; + private static final int port1 = 1111; ServerSocket serverSocket1 = null; @BeforeGroups(groups = "E2E") @@ -132,7 +132,8 @@ public void testMainEror_Case1InvocationError() { .body("code", Matchers.equalTo(500)) .body("bridgeServiceException", Matchers.equalTo(TargetJavaMethodCallException.class.getTypeName())) .body("originalException", Matchers.equalTo(IllegalArgumentException.class.getTypeName())) - .body("stackTrace[0]", Matchers.startsWith(SimpleStaticMethods.class.getTypeName()+"."+ l_calledMethod)); + .body("stackTrace[0]", + Matchers.startsWith(SimpleStaticMethods.class.getTypeName() + "." + l_calledMethod)); } @@ -558,7 +559,6 @@ public void testIntegroIssue() { l_myJavaCalls.getCallContent().put("countries", l_cc); - System.out.println(given().body(l_myJavaCalls).post(EndPointURL + "call").then().extract().asPrettyString()); given().body(l_myJavaCalls).post(EndPointURL + "call").then().assertThat().statusCode(500) @@ -584,7 +584,6 @@ public void testIssueWithInternalError() { "5")); } - @Test(groups = "E2E") public void testInternalErrorCall() { @@ -603,6 +602,27 @@ public void testInternalErrorCall() { } + @Test(groups = "E2E") + public void testExternalErrorCall() { + + JavaCalls l_call = new JavaCalls(); + CallContent myContent = new CallContent(); + myContent.setClassName("com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods"); + myContent.setMethodName("methodCallingMethodThrowingExceptionAndPackingIt"); + myContent.setReturnType("java.lang.String"); + l_call.getCallContent().put("call1PL", myContent); + + given().body(l_call).post(EndPointURL + "call").then().assertThat().statusCode(500) + .body("title", + Matchers.equalTo( + "Error during call of target Java Class and Method.")) + .body("originalException", Matchers.equalTo("java.lang.IllegalArgumentException")) + .body("originalMessage", Matchers.equalTo("Will always throw this")) + .body("stackTrace[0]", Matchers.equalTo( + "com.adobe.campaign.tests.bridge.testdata.one.SimpleStaticMethods.methodThrowsException(SimpleStaticMethods.java:65)")); + + } + @AfterGroups(groups = "E2E", alwaysRun = true) public void tearDown() throws IOException { ConfigValueHandlerIBS.resetAllValues();