Skip to content

Commit

Permalink
Issue 65: Add internal requests stats count
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladay committed May 12, 2020
1 parent 5d572ee commit 92740cb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.web.bind.annotation.RestController;

import edu.tamu.app.model.InternalRequest;
import edu.tamu.app.model.InternalStats;
import edu.tamu.app.model.Product;
import edu.tamu.app.model.RemoteProductManager;
import edu.tamu.app.model.repo.InternalRequestRepo;
Expand Down Expand Up @@ -117,4 +118,9 @@ public ApiResponse push(@PathVariable Long requestId, @PathVariable Long product
return response;
}

@GetMapping("/stats")
public ApiResponse stats() {
return new ApiResponse(SUCCESS, new InternalStats(internalRequestRepo.count()));
}

}
25 changes: 25 additions & 0 deletions src/main/java/edu/tamu/app/model/InternalStats.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package edu.tamu.app.model;

import java.io.Serializable;

public class InternalStats implements Serializable {

private static final long serialVersionUID = -1622544796949909087L;

private final long internalCount;

public InternalStats() {
super();
internalCount = 0;
}

public InternalStats(long internalCount) {
super();
this.internalCount = internalCount;
}

public long getInternalCount() {
return internalCount;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import edu.tamu.app.cache.service.RemoteProductsScheduledCacheService;
import edu.tamu.app.model.InternalRequest;
import edu.tamu.app.model.InternalStats;
import edu.tamu.app.model.Product;
import edu.tamu.app.model.RemoteProductInfo;
import edu.tamu.app.model.RemoteProductManager;
Expand Down Expand Up @@ -272,4 +273,12 @@ public void testPushWhenRemoteProductManagerBeanFails() throws Exception {
assertEquals("Pushing Internal Request when Remote Product Management Bean push fails did not result in an error", ERROR, apiResponse.getMeta().getStatus());
assertEquals("Pushing Internal Request did not result in the expected error message", "Error pushing Internal Request to " + TEST_REMOTE_PRODUCT_MANAGER.getName() + " for Product " + TEST_PRODUCT1_NAME + "!", apiResponse.getMeta().getMessage());
}

@Test
public void testStats() {
ApiResponse apiResponse = internalRequestController.stats();

assertEquals("Request for Internal Request stats was unsuccessful", SUCCESS, apiResponse.getMeta().getStatus());
assertEquals("Number of Internal Requests was not correct", 2L, ((InternalStats) apiResponse.getPayload().get("InternalStats")).getInternalCount());
}
}
18 changes: 18 additions & 0 deletions src/test/java/edu/tamu/app/model/InternalStatsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.tamu.app.model;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
public class InternalStatsTest {

@Test
public void testNewInternalStats() {
InternalStats internalStats = new InternalStats(3);
assertEquals(3, internalStats.getInternalCount());
}

}

0 comments on commit 92740cb

Please sign in to comment.