Skip to content

Commit

Permalink
Merge pull request #15 from KPMP/KPMP-1829_RefactorStateMessages
Browse files Browse the repository at this point in the history
Kpmp 1829 refactor state messages
  • Loading branch information
zwright authored May 28, 2020
2 parents 0ea3aa4 + e004c88 commit ac7fed2
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/main/java/org/kpmp/stateManager/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ public void setState(String state) {
this.state = state;
}

public String getLargeUploadChecked() { return largeUploadChecked; }
public String getLargeUploadChecked() {
return largeUploadChecked;
}

public void setLargeUploadChecked(String largeUploadChecked) { this.largeUploadChecked = largeUploadChecked; }
public void setLargeUploadChecked(String largeUploadChecked) {
this.largeUploadChecked = largeUploadChecked;
}

public String getPackageId() {
return packageId;
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/kpmp/stateManager/StateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public StateController(StateService stateService) {
return stateService.getAllCurrentStates();
}

@RequestMapping(value = "/v1/state/stateDisplayMap", method = RequestMethod.GET)
public @ResponseBody List<StateDisplay> getStateDisplays(HttpServletRequest request) {
log.info("URI: " + request.getRequestURI() + " | MSG: Retrieving state map");
return stateService.getAllStateDisplays();
}

@RequestMapping(value = "/v1/state/events/{afterTime}", method = RequestMethod.GET)
public @ResponseBody DeferredResult<List<State>> getStateEvents(@PathVariable("afterTime") String afterTime,
HttpServletRequest request) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/kpmp/stateManager/StateDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.kpmp.stateManager;

import org.bson.Document;
import org.springframework.data.annotation.Id;

@org.springframework.data.mongodb.core.mapping.Document(collection = "stateDisplay")
public class StateDisplay {

@Id
private String id;
private String state;
private Document apps;

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public Document getApps() {
return apps;
}

public void setApps(Document apps) {
this.apps = apps;
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/kpmp/stateManager/StateDisplayRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.kpmp.stateManager;

import java.util.List;

import org.springframework.data.mongodb.repository.MongoRepository;

public interface StateDisplayRepository extends MongoRepository<StateDisplay, String> {

public List<StateDisplay> findAll();

}
9 changes: 8 additions & 1 deletion src/main/java/org/kpmp/stateManager/StateService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ public class StateService {
@Value("${package.state.upload.succeeded}")
private String uploadSucceededState;
private NotificationHandler notificationHandler;
private StateDisplayRepository stateDisplayRepo;

@Autowired
public StateService(CustomStateRepository stateRepository, NotificationHandler notificationHandler) {
public StateService(CustomStateRepository stateRepository, NotificationHandler notificationHandler,
StateDisplayRepository stateDisplayRepo) {
this.stateRepository = stateRepository;
this.notificationHandler = notificationHandler;
this.stateDisplayRepo = stateDisplayRepo;
}

@CacheEvict(value = "states", allEntries = true)
Expand Down Expand Up @@ -70,4 +73,8 @@ public List<State> getAllCurrentStates() {
return states;
}

public List<StateDisplay> getAllStateDisplays() {
return stateDisplayRepo.findAll();
}

}
8 changes: 8 additions & 0 deletions src/test/java/org/kpmp/stateManager/StateControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,12 @@ public void testGetStates() throws Exception {
verify(stateService).getAllCurrentStates();
}

@Test
public void testGetStateDisplays() throws Exception {
List<StateDisplay> stateDisplays = Arrays.asList(mock(StateDisplay.class));
when(stateService.getAllStateDisplays()).thenReturn(stateDisplays);

assertEquals(stateDisplays, controller.getStateDisplays(mock(HttpServletRequest.class)));
}

}
47 changes: 47 additions & 0 deletions src/test/java/org/kpmp/stateManager/StateDisplayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.kpmp.stateManager;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

import org.bson.Document;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;

public class StateDisplayTest {

private StateDisplay stateDisplay;

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
stateDisplay = new StateDisplay();
}

@After
public void tearDown() throws Exception {
stateDisplay = null;
}

@Test
public void testSetState() {
stateDisplay.setState("state");
assertEquals("state", stateDisplay.getState());
}

@Test
public void testSetId() {
stateDisplay.setId("displayId");
assertEquals("displayId", stateDisplay.getId());
}

@Test
public void testSetApps() throws Exception {
Document apps = mock(Document.class);
stateDisplay.setApps(apps);

assertEquals(apps, stateDisplay.getApps());
}

}
12 changes: 11 additions & 1 deletion src/test/java/org/kpmp/stateManager/StateServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ public class StateServiceTest {
private StateService service;
@Mock
private NotificationHandler notificationHandler;
@Mock
private StateDisplayRepository stateDisplayRepo;

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
service = new StateService(stateRepository, notificationHandler);
service = new StateService(stateRepository, notificationHandler, stateDisplayRepo);
ReflectionTestUtils.setField(service, "uploadFailedState", "UPLOAD_FAILED");
ReflectionTestUtils.setField(service, "uploadSucceededState", "UPLOAD_SUCCEEDED");
}
Expand Down Expand Up @@ -137,4 +139,12 @@ public void testIsPackageFailedFalse() throws Exception {
when(stateRepository.findPackageByIdAndByState("1234", "UPLOAD_FAILED")).thenReturn(null);
assertEquals(false, service.isPackageFailed("1234"));
}

@Test
public void testGetStateDisplays() throws Exception {
List<StateDisplay> stateDisplays = Arrays.asList(mock(StateDisplay.class));
when(stateDisplayRepo.findAll()).thenReturn(stateDisplays);

assertEquals(stateDisplays, service.getAllStateDisplays());
}
}

0 comments on commit ac7fed2

Please sign in to comment.