Skip to content

Commit

Permalink
#79 first working commit
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed May 4, 2024
1 parent a06cb6f commit bfd29a3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import spark.Request;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.stream.Collectors;

import static spark.Spark.*;

Expand Down Expand Up @@ -77,6 +80,8 @@ public static void startServices(int port) {
post("/call", (req, res) -> {
JavaCalls fetchedFromJSON = BridgeServiceFactory.createJavaCalls(req.body());

fetchedFromJSON.addHeaders(req.headers().stream().collect(Collectors.toMap(k -> k, k -> req.headers(k))));

return BridgeServiceFactory.transformJavaCallResultsToJSON(fetchedFromJSON.submitCalls());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,12 @@ public Map<String, Assertion> getAssertions() {
public void setAssertions(Map<String, Assertion> assertions) {
this.assertions = assertions;
}

/**
* Adds headers to the results cache of the ClassLoader
* @param in_mapOHeaders A map containing header values coming from the request
*/
public void addHeaders(Map<String, String> in_mapOHeaders) {
in_mapOHeaders.forEach((k,v) -> this.getLocalClassLoader().getCallResultCache().put(k,v));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,26 @@ public void testAssertionsHelloWorldCall() {

}


@Test(description = "Issue #78 accepting header secrets", groups = "E2E")
public void testFetchHeaders() {
JavaCalls l_myJavaCall = new JavaCalls();

CallContent l_cc = new CallContent();
l_cc.setClassName(SimpleStaticMethods.class.getTypeName());
l_cc.setMethodName("methodAcceptingStringArgument");
l_cc.setArgs(new Object[] { "IBS_HEADER_1" });

l_myJavaCall.getCallContent().put("fetchString", l_cc);

given().body(l_myJavaCall).header("IBS_HEADER_1","REAL").post(EndPointURL + "call").then().assertThat()
.body("returnValues.fetchString", Matchers.equalTo("REAL_Success"));

}

@AfterGroups(groups = "E2E", alwaysRun = true)
public void tearDown() throws IOException {

ConfigValueHandlerIBS.resetAllValues();
Spark.stop();
serverSocket1.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.adobe.campaign.tests.bridge.testdata.two.StaticMethodsIntegrity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.hamcrest.Matchers;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
Expand Down Expand Up @@ -1383,7 +1382,6 @@ public void testDurationReplacement() {
Long result3 = jcr.expandDurations(100);
assertThat(result3, Matchers.equalTo(100l));


}

@Test
Expand Down Expand Up @@ -2057,5 +2055,20 @@ public void testWithErrorAtEnvironmentValue() {

}
}

//Managing headers
@Test
public void testUsingHeaders() {
Map<String, String> l_headerMap = Map.of("key1", "value1", "key2", "value2");

JavaCalls l_myJavaCalls = new JavaCalls();

assertThat("We should not have any call results yet", l_myJavaCalls.getLocalClassLoader().getCallResultCache(),
Matchers.anEmptyMap());

l_myJavaCalls.addHeaders(l_headerMap);
assertThat("We should not have any call results yet", l_myJavaCalls.getLocalClassLoader().getCallResultCache().size(),
Matchers.equalTo(2));
}
}

0 comments on commit bfd29a3

Please sign in to comment.