Skip to content

Commit

Permalink
rebased staging, more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Jul 12, 2018
2 parents 10df7a7 + 106b99b commit 33fb23a
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 20 deletions.
15 changes: 7 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
Expand Down Expand Up @@ -81,12 +80,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.versionone</groupId>
<artifactId>VersionOne.SDK.Java.APIClient</artifactId>
<version>16.1.0</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand All @@ -106,6 +99,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.versionone</groupId>
<artifactId>VersionOne.SDK.Java.APIClient</artifactId>
<version>16.1.0</version>
</dependency>

</dependencies>

<build>
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/edu/tamu/app/model/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package edu.tamu.app.model;

import java.util.List;

public class Card {

// Identifier for the card
private final String name;

// Title displayed above the card body
private final String title;

private final String body;

private final String estimate;

private final List<Member> members;

private final String status;

private final String type;

public Card(String name, String title, String body, String estimate, List<Member> members, String status, String type) {
this.name = name;
this.title = title;
this.body = body;
this.estimate = estimate;
this.members = members;
this.status = status;
this.type = type;
}

public String getName() {
return name;
}

public String getTitle() {
return title;
}

public String getBody() {
return body;
}

public String getEstimate() {
return estimate;
}

public List<Member> getMembers() {
return members;
}

public String getStatus() {
return status;
}

public String getType() {
return type;
}

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

public class Member {

private final String name;

private final String avatarUrl;

public Member(String name, String avatarUrl) {
this.name = name;
this.avatarUrl = avatarUrl;
}

public String getName() {
return name;
}

public String getAvatarUrl() {
return avatarUrl;
}

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

import java.util.List;

public class Sprint {

private final String identifier;

private final String name;

private final String projectName;

private final List<Card> cards;

public Sprint(String identifier, String name, String projectName, List<Card> cards) {
this.identifier = identifier;
this.name = name;
this.projectName = projectName;
this.cards = cards;
}

public String getIdentifier() {
return identifier;
}

public String getName() {
return name;
}

public String getProjectName() {
return projectName;
}

public List<Card> getCards() {
return cards;
}

}
19 changes: 13 additions & 6 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ spring.jpa.show_sql: false
spring.jpa.hibernate.ddl-auto: create-drop


spring.thymeleaf.cache: false
spring.thymeleaf.mode: XML
spring.thymeleaf.prefix: classpath:/templates/
spring.thymeleaf.suffix: .xml
spring.thymeleaf.content-type: text/xml

# logging
logging.level.org.tdl: INFO
logging.level.edu.tamu: INFO
Expand All @@ -57,6 +51,19 @@ app.cache.remote-projects.delay: 2000
# 24 hours in milliseconds
app.cache.remote-projects.interval: 86400000

################################################################
# edu.tamu.app.service.SprintsCacheService
# 10 minutes in milliseconds: (10 * 60 * 1000)
app.sprint.cache.interval: 600000
# 10 seconds in milliseconds: (10 * 1000)
app.sprint.cache.delay: 10000
################################################################

################################################################
# edu.tamu.app.service.versioning.VersionOneService
app.vms.versionone.avatar: https://www15.v1host.com/s/18.1.4.12/css/images/no_avatar.png
################################################################

################################################################
# edu.tamu.weaver.auth.service.UserCredentialsService
app.authority.admins: 123456789, 990000081, 523008230, 512004707, 613001223, 402001311
Expand Down
62 changes: 62 additions & 0 deletions src/test/java/edu/tamu/app/cache/RemoteProjectsCacheTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package edu.tamu.app.cache;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import edu.tamu.app.cache.model.RemoteProject;

@RunWith(SpringRunner.class)
public class RemoteProjectsCacheTest {

@Test
public void testNewRemoteProjectsCache() {
RemoteProjectsCache cache = new RemoteProjectsCache();
assertNotNull("New remote project cache was not created!", cache);
assertNotNull("New remote project cache remoteProjects were not created!", cache.get());
}

@Test
public void testSetCache() {
RemoteProjectsCache cache = new RemoteProjectsCache();
assertTrue("Cached remote projects was not empty!", cache.get().isEmpty());
Map<Long, List<RemoteProject>> remoteProjectMap = new HashMap<Long, List<RemoteProject>>();
List<RemoteProject> remoteProjects = new ArrayList<RemoteProject>();
remoteProjects.add(getMockRemoteProject());
remoteProjectMap.put(1L, remoteProjects);
cache.set(remoteProjectMap);
assertFalse("Cached remoteProjects was empty!", cache.get().isEmpty());
}

@Test
public void testGetCache() {
RemoteProjectsCache cache = new RemoteProjectsCache();
Map<Long, List<RemoteProject>> remoteProjectMap = new HashMap<Long, List<RemoteProject>>();
List<RemoteProject> remoteProjects = new ArrayList<RemoteProject>();
remoteProjects.add(getMockRemoteProject());
remoteProjectMap.put(1L, remoteProjects);
cache.set(remoteProjectMap);
Map<Long, List<RemoteProject>> remoteProjectsCache = cache.get();
assertFalse("Cached remote projects was empty!", remoteProjectsCache.isEmpty());
assertEquals("Cached remote projects had incorrect number of remote projects!", 1, remoteProjectsCache.size());
assertEquals("Cached remote projects did not have expected remote projects for a given remote project manager!", 1, remoteProjectsCache.get(1L).size());

assertEquals("Cached remote project had incorrect id!", "0001", remoteProjectsCache.get(1L).get(0).getScopeId());
assertEquals("Cached remote project had incorrect name!", "Remote Project 1", remoteProjectsCache.get(1L).get(0).getName());
}

private RemoteProject getMockRemoteProject() {
return new RemoteProject("0001", "Remote Project 1");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package edu.tamu.app.cache.controller;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.test.context.junit4.SpringRunner;

import edu.tamu.app.cache.model.RemoteProject;
import edu.tamu.app.cache.service.RemoteProjectsScheduledCacheService;
import edu.tamu.weaver.response.ApiResponse;
import edu.tamu.weaver.response.ApiStatus;

@RunWith(SpringRunner.class)
public class RemoteProjectsCacheControllerTest {

@Mock
private RemoteProjectsScheduledCacheService remoteProjectsScheduledCacheService;

@InjectMocks
private RemoteProjectsCacheController remoteProjectsCacheController;

@Before
public void setup() throws Exception {
MockitoAnnotations.initMocks(this);
when(remoteProjectsScheduledCacheService.get()).thenReturn(getMockRemoteProjectsCache());
}

@Test
@SuppressWarnings("unchecked")
public void testGet() {
ApiResponse response = remoteProjectsCacheController.get();
assertNotNull("Reponse was null!", response);
assertEquals("Reponse was not successfull!", ApiStatus.SUCCESS, response.getMeta().getStatus());

assertNotNull("Reponse payload did not have expected property!", response.getPayload().get("HashMap"));
assertRemoteProjects((Map<Long, List<RemoteProject>>) response.getPayload().get("HashMap"));
}

@Test
public void testUpdate() {
ApiResponse response = remoteProjectsCacheController.update();
assertNotNull(response);
assertEquals(ApiStatus.SUCCESS, response.getMeta().getStatus());
verify(remoteProjectsScheduledCacheService, times(1)).update();
verify(remoteProjectsScheduledCacheService, times(1)).broadcast();
}

private void assertRemoteProjects(Map<Long, List<RemoteProject>> remoteProjectsCache) {
assertFalse(remoteProjectsCache.isEmpty());
assertEquals(1, remoteProjectsCache.size());
List<RemoteProject> remoteProjects = remoteProjectsCache.get(1L);
assertFalse(remoteProjects.isEmpty());
assertEquals(1, remoteProjects.size());
assertEquals("0001", remoteProjects.get(0).getScopeId());
assertEquals("Remote Project 1", remoteProjects.get(0).getName());
}

private Map<Long, List<RemoteProject>> getMockRemoteProjectsCache() {
Map<Long, List<RemoteProject>> remoteProjectCache = new HashMap<Long, List<RemoteProject>>();
List<RemoteProject> remoteProjects = new ArrayList<RemoteProject>();
remoteProjects.add(getMockRemoteProject());
remoteProjectCache.put(1L, remoteProjects);
return remoteProjectCache;
}

private RemoteProject getMockRemoteProject() {
return new RemoteProject("0001", "Remote Project 1");
}

}

0 comments on commit 33fb23a

Please sign in to comment.