use of com.redhat.cloud.notifications.routers.models.EndpointPage in project notifications-backend by RedHatInsights.
the class EndpointResourceTest method testSearch.
@Test
void testSearch() {
String tenant = "search";
String orgId = "search2";
String userName = "user";
String identityHeaderValue = TestHelpers.encodeRHIdentityInfo(tenant, orgId, userName);
Header identityHeader = TestHelpers.createRHIdentityHeader(identityHeaderValue);
MockServerConfig.addMockRbacAccess(identityHeaderValue, MockServerConfig.RbacAccess.FULL_ACCESS);
addEndpoints(10, identityHeader);
Response response = given().header(identityHeader).queryParam("limit", "20").queryParam("offset", "0").queryParam("name", "2").when().get("/endpoints").then().statusCode(200).contentType(JSON).extract().response();
EndpointPage endpointPage = Json.decodeValue(response.getBody().asString(), EndpointPage.class);
assertEquals(1, endpointPage.getMeta().getCount());
assertEquals(1, endpointPage.getData().size());
assertEquals("Endpoint 2", endpointPage.getData().get(0).getName());
response = given().header(identityHeader).queryParam("limit", "20").queryParam("offset", "0").queryParam("name", "foo").when().get("/endpoints").then().statusCode(200).contentType(JSON).extract().response();
endpointPage = Json.decodeValue(response.getBody().asString(), EndpointPage.class);
assertEquals(0, endpointPage.getMeta().getCount());
assertEquals(0, endpointPage.getData().size());
}
use of com.redhat.cloud.notifications.routers.models.EndpointPage in project notifications-backend by RedHatInsights.
the class EndpointResourceTest method testEndpointTypeQuery.
@ParameterizedTest
@MethodSource
void testEndpointTypeQuery(Set<EndpointType> types) {
String tenant = "limiter";
String orgId = "limiter2";
String userName = "user";
String identityHeaderValue = TestHelpers.encodeRHIdentityInfo(tenant, orgId, userName);
Header identityHeader = TestHelpers.createRHIdentityHeader(identityHeaderValue);
MockServerConfig.addMockRbacAccess(identityHeaderValue, MockServerConfig.RbacAccess.FULL_ACCESS);
// Add webhook
WebhookProperties properties = new WebhookProperties();
properties.setMethod(HttpType.POST);
properties.setDisableSslVerification(false);
properties.setSecretToken("my-super-secret-token");
properties.setUrl(getMockServerUrl());
Endpoint ep = new Endpoint();
ep.setType(EndpointType.WEBHOOK);
ep.setName("endpoint to find");
ep.setDescription("needle in the haystack");
ep.setEnabled(true);
ep.setProperties(properties);
Response response = given().header(identityHeader).when().contentType(JSON).body(Json.encode(ep)).post("/endpoints").then().statusCode(200).contentType(JSON).extract().response();
JsonObject responsePoint = new JsonObject(response.getBody().asString());
responsePoint.mapTo(Endpoint.class);
assertNotNull(responsePoint.getString("id"));
// Add Camel
CamelProperties camelProperties = new CamelProperties();
camelProperties.setDisableSslVerification(false);
camelProperties.setSecretToken("my-super-secret-token");
camelProperties.setUrl(getMockServerUrl());
camelProperties.setExtras(new HashMap<>());
Endpoint camelEp = new Endpoint();
camelEp.setType(EndpointType.CAMEL);
camelEp.setSubType("demo");
camelEp.setName("endpoint to find");
camelEp.setDescription("needle in the haystack");
camelEp.setEnabled(true);
camelEp.setProperties(camelProperties);
response = given().header(identityHeader).when().contentType(JSON).body(Json.encode(camelEp)).post("/endpoints").then().statusCode(200).contentType(JSON).extract().response();
responsePoint = new JsonObject(response.getBody().asString());
responsePoint.mapTo(Endpoint.class);
assertNotNull(responsePoint.getString("id"));
// Fetch the list to ensure everything was inserted correctly.
response = given().header(identityHeader).when().get("/endpoints").then().statusCode(200).contentType(JSON).extract().response();
EndpointPage endpointPage = Json.decodeValue(response.getBody().asString(), EndpointPage.class);
List<Endpoint> endpoints = endpointPage.getData();
assertEquals(2, endpoints.size());
// Fetch the list with types
response = given().header(identityHeader).queryParam("type", types).when().get("/endpoints").then().statusCode(200).contentType(JSON).extract().response();
endpointPage = Json.decodeValue(response.getBody().asString(), EndpointPage.class);
endpoints = endpointPage.getData();
// Ensure there is only the requested types
assertEquals(types, endpoints.stream().map(Endpoint::getType).collect(Collectors.toSet()));
}
use of com.redhat.cloud.notifications.routers.models.EndpointPage in project notifications-backend by RedHatInsights.
the class EndpointResource method getEndpoints.
@GET
@Produces(APPLICATION_JSON)
@RolesAllowed(ConsoleIdentityProvider.RBAC_READ_INTEGRATIONS_ENDPOINTS)
@Parameters({ @Parameter(name = "limit", in = ParameterIn.QUERY, description = "Number of items per page. If the value is 0, it will return all elements", schema = @Schema(type = SchemaType.INTEGER)), @Parameter(name = "pageNumber", in = ParameterIn.QUERY, description = "Page number. Starts at first page (0), if not specified starts at first page.", schema = @Schema(type = SchemaType.INTEGER)) })
public EndpointPage getEndpoints(@Context SecurityContext sec, @BeanParam Query query, @QueryParam("type") List<String> targetType, @QueryParam("active") Boolean activeOnly, @QueryParam("name") String name) {
RhIdPrincipal principal = (RhIdPrincipal) sec.getUserPrincipal();
List<Endpoint> endpoints;
Long count;
if (targetType != null && targetType.size() > 0) {
Set<CompositeEndpointType> compositeType = targetType.stream().map(s -> {
try {
return CompositeEndpointType.fromString(s);
} catch (IllegalArgumentException e) {
throw new BadRequestException("Unknown endpoint type: [" + s + "]", e);
}
}).collect(Collectors.toSet());
endpoints = endpointRepository.getEndpointsPerCompositeType(principal.getAccount(), name, compositeType, activeOnly, query);
count = endpointRepository.getEndpointsCountPerCompositeType(principal.getAccount(), name, compositeType, activeOnly);
} else {
endpoints = endpointRepository.getEndpoints(principal.getAccount(), name, query);
count = endpointRepository.getEndpointsCount(principal.getAccount(), name);
}
return new EndpointPage(endpoints, new HashMap<>(), new Meta(count));
}
Aggregations