Skip to content

Commit

Permalink
fix: internal api
Browse files Browse the repository at this point in the history
  • Loading branch information
vkrizan committed Apr 9, 2024
1 parent a0c5513 commit e4ab45e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.Response;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -119,14 +118,14 @@ public Response getStats() {
long totalCount = Policy.count();
Map<String, Integer> buckets = populateBuckets();

List<Object[]> list = entityManager.createNativeQuery("select p.customerId,count (p) from policy p group by p.customerId")
List<Object[]> list = entityManager.createNativeQuery("select p.customerid,count (p) from policy p group by p.customerid")
.getResultList();
System.out.println(list.size());
long cCount = list.size();

Map<String, Object> idsMap = new HashMap<>();
idsMap.put("ids", filterIds);
long fcount = Policy.count("customerId in (:ids)", idsMap);
long fcount = Policy.count("customerid in (:ids)", idsMap);

final long[] filteredIdsCount = {0};
list.forEach(i -> {
Expand All @@ -135,7 +134,7 @@ public Response getStats() {
if (filterIds.contains(cid)) {
filteredIdsCount[0]++;
}
int count = ((BigInteger) i[1]).intValue();
long count = (long) i[1];
putToBucket(buckets, count);
});

Expand All @@ -158,7 +157,7 @@ private Map<String, Integer> populateBuckets() {
return map;
}

private void putToBucket(Map<String, Integer> buckets, int count) {
private void putToBucket(Map<String, Integer> buckets, long count) {
String bucket;

if (count < 5) {
Expand Down
50 changes: 50 additions & 0 deletions src/test/java/com/redhat/cloud/policies/app/AdminServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.redhat.cloud.policies.app;

import static io.restassured.RestAssured.given;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@QuarkusTest
@QuarkusTestResource(TestLifecycleManager.class)
@Tag("integration")
class AdminServiceTest extends AbstractITest {

@Test
void testStatsSmoke() {
given()
.when().get("/admin/stats")
.then()
.statusCode(200);
}

@Test
void testStatusSmoke() {
given()
.when()
.contentType(ContentType.JSON)
.post("/admin/status")
.then()
.statusCode(200);
}
}

0 comments on commit e4ab45e

Please sign in to comment.