use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class DatahubRestResourceAuditEventConverterTest method testRequestParametersWhenStackFoundAndScaling.
@Test
public void testRequestParametersWhenStackFoundAndScaling() {
StructuredRestCallEvent event = new StructuredRestCallEvent();
OperationDetails operation = new OperationDetails();
operation.setResourceName("name");
operation.setWorkspaceId(123L);
operation.setResourceEvent("scaling");
event.setOperation(operation);
RestCallDetails restCall = new RestCallDetails();
event.setRestCall(restCall);
RestRequestDetails restRequest = new RestRequestDetails();
restRequest.setMethod("PUT");
restRequest.setBody(new Json(Map.of("group", "gr", "desiredCount", 2)).getValue());
restCall.setRestRequest(restRequest);
Stack stack = new Stack();
Cluster cluster = new Cluster();
cluster.setId(345L);
stack.setCluster(cluster);
HostGroup hostGroup = new HostGroup();
InstanceGroup instanceGroup = new InstanceGroup();
hostGroup.setInstanceGroup(instanceGroup);
Map<String, Object> params = new HashMap<>();
when(legacyRestCommonService.addClusterCrnAndNameIfPresent(event)).thenReturn(params);
when(stackService.findStackByNameAndWorkspaceId(operation.getResourceName(), operation.getWorkspaceId())).thenReturn(Optional.of(stack));
when(hostGroupService.getByClusterIdAndNameWithRecipes(345L, "gr")).thenReturn(hostGroup);
Map<String, Object> actual = underTest.requestParameters(event);
Assertions.assertEquals(3, actual.size());
Assertions.assertEquals(2, actual.get("desiredCount"));
Assertions.assertEquals(0, actual.get("originalCount"));
Assertions.assertEquals("gr", actual.get("hostGroup"));
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class KafkaStructuredEventHandlerTest method createDummyStructuredRestEvent.
private StructuredRestCallEvent createDummyStructuredRestEvent() {
RestRequestDetails requestDetails = new RestRequestDetails();
requestDetails.setBody("RequestBodyContent");
requestDetails.setRequestUri("/v3/clusters");
RestResponseDetails restResponseDetails = new RestResponseDetails();
restResponseDetails.setStatusCode(200);
restResponseDetails.setBody("BodyContent");
restResponseDetails.setHeaders(ImmutableMap.of("content-length", "89"));
RestCallDetails restCallDetails = new RestCallDetails();
restCallDetails.setRestRequest(requestDetails);
restCallDetails.setRestResponse(restResponseDetails);
StructuredRestCallEvent restEvent = new StructuredRestCallEvent();
restEvent.setRestCall(restCallDetails);
restEvent.setType("StructuredRestCallEvent");
return restEvent;
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class KafkaStructuredEventHandlerTest method checkIfPropertiesGetFilteredWithCustomMapper.
@Test
public void checkIfPropertiesGetFilteredWithCustomMapper() {
StructuredRestCallEvent restEvent = createDummyStructuredRestEvent();
classIntest.sanitizeSensitiveRestData(restEvent);
RestRequestDetails requestDetails = restEvent.getRestCall().getRestRequest();
assertTrue("Should be sanitized from Kafka event", requestDetails.getBody().contains(REPLACEMENT));
assertTrue("Should be empty because of ", requestDetails.getHeaders().isEmpty());
assertTrue("Should be left intact", requestDetails.getRequestUri().equals("/v3/clusters"));
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class FreeIpaCustomCrnOrNameProviderTest method testProviderWhenHasQueryParamsAndContainsEnvironmentCrn.
@Test
public void testProviderWhenHasQueryParamsAndContainsEnvironmentCrn() {
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails restRequestDetails = new RestRequestDetails();
restCallDetails.setRestRequest(restRequestDetails);
restRequestDetails.setRequestUri("http://localhost/any/path?environment=env-crn");
String userCrn = CrnTestUtil.getUserCrnBuilder().setAccountId("acc").setResource("res").build().toString();
Stack stack = new Stack();
stack.setName("stackName");
stack.setResourceCrn("stackCrn");
stack.setId(2922L);
when(stackService.findMultipleByEnvironmentCrnAndAccountIdEvenIfTerminated("env-crn", "acc")).thenReturn(List.of(stack));
Map<String, String> restParams = new HashMap<>();
Map<String, String> expected = ThreadBasedUserCrnProvider.doAs(userCrn, () -> underTest.provide(restCallDetails, null, restParams, "name", "crn"));
Assertions.assertEquals("stackName", expected.get("name"));
Assertions.assertEquals("stackCrn", expected.get("crn"));
Assertions.assertEquals("2922", expected.get(RESOURCE_ID));
}
use of com.sequenceiq.cloudbreak.structuredevent.event.rest.RestRequestDetails in project cloudbreak by hortonworks.
the class FreeIpaCustomCrnOrNameProviderTest method testProviderWhenNoQueryParams.
@Test
public void testProviderWhenNoQueryParams() {
RestCallDetails restCallDetails = new RestCallDetails();
RestRequestDetails restRequestDetails = new RestRequestDetails();
restCallDetails.setRestRequest(restRequestDetails);
restRequestDetails.setRequestUri("http://localhost/any/path");
Map<String, String> restParams = new HashMap<>();
underTest.provide(restCallDetails, null, restParams, "name", "crn");
Assertions.assertFalse(restParams.containsKey("name"));
Assertions.assertFalse(restParams.containsKey("crn"));
}
Aggregations