Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 65: Add internal requests stats count #80

Merged
merged 2 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 @@ public ApiResponse push(@PathVariable Long requestId, @PathVariable Long product
return response;
}

@PreAuthorize("hasRole('ANONYMOUS')")
@GetMapping("/stats")
rladdusaw marked this conversation as resolved.
Show resolved Hide resolved
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());
}

}