use of org.hisp.dhis.sms.config.GenericGatewayParameter in project dhis2-core by dhis2.
the class GenericSmsGatewayTest method setUp.
@BeforeEach
public void setUp() {
subject = new SimplisticHttpGetGateWay(restTemplate, pbeStringEncryptor);
gatewayConfig = new GenericHttpGatewayConfig();
gatewayConfig.setUseGet(false);
gatewayConfig.setName("generic");
gatewayConfig.setUrlTemplate(GATEWAY_URL);
gatewayConfig.setDefault(true);
gatewayConfig.setUid(UID);
username = new GenericGatewayParameter();
username.setKey("user");
username.setValue("user_uio");
username.setEncode(false);
username.setHeader(true);
username.setConfidential(false);
password = new GenericGatewayParameter();
password.setKey("password");
password.setValue("abc123");
password.setEncode(false);
password.setHeader(true);
password.setConfidential(true);
valueStore.put(SmsGateway.KEY_TEXT, SmsUtils.encode(TEXT));
valueStore.put(SmsGateway.KEY_RECIPIENT, StringUtils.join(RECIPIENTS, ","));
}
use of org.hisp.dhis.sms.config.GenericGatewayParameter in project dhis2-core by dhis2.
the class GenericSmsGatewayTest method testSendSms_Json.
@Test
void testSendSms_Json() {
strSubstitutor = new StringSubstitutor(valueStore);
body = strSubstitutor.replace(CONFIG_TEMPLATE_JSON);
gatewayConfig.getParameters().clear();
gatewayConfig.setParameters(Arrays.asList(username, password));
gatewayConfig.setContentType(ContentType.APPLICATION_JSON);
gatewayConfig.setConfigurationTemplate(CONFIG_TEMPLATE_JSON);
ResponseEntity<String> responseEntity = new ResponseEntity<>("success", HttpStatus.OK);
when(restTemplate.exchange(any(URI.class), any(HttpMethod.class), any(HttpEntity.class), eq(String.class))).thenReturn(responseEntity);
assertThat(subject.send(SUBJECT, TEXT, RECIPIENTS, gatewayConfig).isOk(), is(true));
verify(restTemplate).exchange(any(URI.class), httpMethodArgumentCaptor.capture(), httpEntityArgumentCaptor.capture(), eq(String.class));
assertNotNull(httpEntityArgumentCaptor.getValue());
assertNotNull(httpMethodArgumentCaptor.getValue());
HttpMethod httpMethod = httpMethodArgumentCaptor.getValue();
assertEquals(HttpMethod.POST, httpMethod);
HttpEntity<String> requestEntity = httpEntityArgumentCaptor.getValue();
assertEquals(body, requestEntity.getBody());
HttpHeaders httpHeaders = requestEntity.getHeaders();
assertTrue(httpHeaders.get("Content-type").contains(gatewayConfig.getContentType().getValue()));
List<GenericGatewayParameter> parameters = gatewayConfig.getParameters();
parameters.stream().filter(p -> p.isEncode() && p.isConfidential() && p.isHeader()).forEach(p -> {
assertTrue(httpHeaders.containsKey(p.getKey()));
assertEquals(" Basic ZGVjcnlwdGVkVGV4dA==", httpHeaders.get(p.getKey()).get(0));
});
}
Aggregations