Merge branches 'PAN-15' and 'master' of https://github.com/atusa17/ptp into PAN-15

# Conflicts:
#	build.gradle
#	persistence/src/main/java/edu/msudenver/tsp/persistence/repository/AccountsRepository.java
#	persistence/src/test/java/edu/msudenver/tsp/persistence/controller/AccountControllerTest.java
#	services/src/main/java/edu/msudenver/tsp/services/RestService.java
#	services/src/main/java/edu/msudenver/tsp/services/dto/Account.java
#	services/src/main/java/edu/msudenver/tsp/services/factory/RequestFactory.java
#	services/src/main/java/edu/msudenver/tsp/services/parser/ParserService.java
#	services/src/test/java/edu/msudenver/tsp/services/parser/ParserServiceTest.java
This commit is contained in:
2019-03-20 22:15:32 -06:00
43 changed files with 1972 additions and 399 deletions
@@ -43,20 +43,20 @@ public class RestService {
return send(requestFactory.post(uri, requestJson), null, connectionTimeout, socketTimeout, type);
}
<T> Optional<T> patch(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout) {
LOG.info("Sending Patch {} with body: {}", uri, requestJson);
return send(requestFactory.patch(uri, requestJson), null, connectionTimeout, socketTimeout, type);
}
Optional<HttpResponse> post(final String uri, final String requestJson, final Integer connectionTimeout, final Integer socketTimeout) {
LOG.info("Sending POST {} with body: {}", uri, requestJson);
return send(requestFactory.post(uri, requestJson), null, connectionTimeout, socketTimeout);
}
<T> Optional<T> put(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout) {
<T> Optional<T> put(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout, final String auth) {
LOG.info("Sending PUT {} with body: {}", uri, requestJson);
return send(requestFactory.put(uri, requestJson), null, connectionTimeout, socketTimeout, type);
return send(requestFactory.put(uri, requestJson), auth, connectionTimeout, socketTimeout, type);
}
<T> Optional<T> patch(final String uri, final String requestJson, final TypeToken<T> type, final Integer connectionTimeout, final Integer socketTimeout) {
LOG.info("Sending PATCH {} with body: {}", uri, requestJson);
return send(requestFactory.patch(uri, requestJson), null, connectionTimeout, socketTimeout, type);
}
private <T> Optional<T> send(final Request request, final String auth, final Integer connectionTimeout, final Integer socketTimeout, final TypeToken<T> type) {
try {
@@ -6,6 +6,7 @@ import lombok.EqualsAndHashCode;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
@@ -14,12 +15,11 @@ import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = true)
public class Account extends BaseDto implements Serializable {
@Size(max = 50) private String username;
@Size(max = 256) private String password;
@NotBlank(groups = edu.msudenver.tsp.persistence.dto.Account.Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
@NotBlank(groups = edu.msudenver.tsp.persistence.dto.Account.Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
@NotNull @SerializedName("administrator_status") private boolean administratorStatus;
@Temporal(TemporalType.DATE) @SerializedName("last_login") private Date lastLogin;
private static final long serialVersionUID = 7095627971593953734L;
}
@@ -24,6 +24,6 @@ public class RequestFactory {
}
public Request patch(final String uri, final String requestJson) {
return StringUtils.isNotBlank(requestJson) ? Request.Patch(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Patch(uri);
return StringUtils.isNotBlank(requestJson) ? Request.Put(uri).bodyString(requestJson, ContentType.APPLICATION_JSON) : Request.Patch(uri);
}
}
@@ -1,23 +1,24 @@
package edu.msudenver.tsp.services.parser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
class ParserService {
private Node root;
public boolean parseUserInput(final String userInput)
{
try {
final Node tree = parseRawInput(userInput);
final List<String> statements = retrieveStatements(tree);
retrieveStatements(tree);
return true;
} catch(final Exception e) {
e.printStackTrace();
LOG.error(e.getMessage());
}
return false;
}
@@ -26,7 +27,7 @@ class ParserService {
{
input = input.toLowerCase();
root = new Node(input, null);
final Node root = new Node(input, null);
if(input.equals(""))
{
@@ -1,16 +0,0 @@
package edu.msudenver.tsp.services.scoring;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan
//@PropertySource("classpath:development.properties")
public class ScoringConfig {
@Bean
public TheoremScoringService theoremScoringService() {
return new TheoremScoringService();
}
}
@@ -1,8 +0,0 @@
package edu.msudenver.tsp.services.scoring;
import org.springframework.stereotype.Service;
@Service
class TheoremScoringService {
}
@@ -0,0 +1,66 @@
package edu.msudenver.tsp.services.factory;
import org.apache.http.client.fluent.Request;
import org.junit.Test;
import static org.junit.Assert.assertNotNull;
public class RequestFactoryTest {
private final RequestFactory requestFactory = new RequestFactory();
@Test
public void testDelete() {
final Request testRequest = requestFactory.delete("testUri");
assertNotNull(testRequest);
}
@Test
public void testGet() {
final Request testRequest = requestFactory.get("testUri");
assertNotNull(testRequest);
}
@Test
public void testPost() {
final Request testRequest = requestFactory.post("testUri", "testJson");
assertNotNull(testRequest);
}
@Test
public void testPost_blankRequestJson() {
final Request testRequest = requestFactory.post("testUri", null);
assertNotNull(testRequest);
}
@Test
public void testPut() {
final Request testRequest = requestFactory.put("testUri", "testJson");
assertNotNull(testRequest);
}
@Test
public void testPut_blankRequestJson() {
final Request testRequest = requestFactory.put("testUri", null);
assertNotNull(testRequest);
}
@Test
public void testPatch() {
final Request testRequest = requestFactory.patch("testUri", "testJson");
assertNotNull(testRequest);
}
@Test
public void testPatch_blankRequestJson() {
final Request testRequest = requestFactory.patch("testUri", null);
assertNotNull(testRequest);
}
}
@@ -2,7 +2,8 @@ package edu.msudenver.tsp.services.parser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Spy;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.ArrayList;
@@ -16,7 +17,9 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class ParserServiceTest {
@Spy private ParserService parserService;
@Mock private ParserService mockParserService;
@InjectMocks private ParserService parserService;
@Test
public void testEmptyStringEqualsEmptyString() {
@@ -99,8 +102,8 @@ public class ParserServiceTest {
final List<String> expectedList = new ArrayList<>();
expectedList.add("");
when(parserService.parseRawInput(anyString())).thenReturn(new Node("", null));
final List<String> actualList = parserService.retrieveStatements(parserService.parseRawInput(""));
when(mockParserService.parseRawInput(anyString())).thenReturn(new Node("", null));
final List<String> actualList = parserService.retrieveStatements(mockParserService.parseRawInput(""));
assertEquals(expectedList, actualList);
}
@@ -117,8 +120,8 @@ public class ParserServiceTest {
testNode.setRight(new Node("then", testNode));
testNode.getRight().setCenter(new Node(" x^2 is even", testNode.getRight()));
when(parserService.parseRawInput(anyString())).thenReturn(testNode);
final List<String> actualList = parserService.retrieveStatements(parserService.parseRawInput("baseCase"));
when(mockParserService.parseRawInput(anyString())).thenReturn(testNode);
final List<String> actualList = parserService.retrieveStatements(mockParserService.parseRawInput("baseCase"));
assertEquals(expectedList, actualList);
}
@@ -126,8 +129,8 @@ public class ParserServiceTest {
@Test
public void testDriveParseUserInput() {
final Node testNode = new Node("", null);
when(parserService.parseRawInput(anyString())).thenReturn(testNode);
when(parserService.retrieveStatements(testNode)).thenReturn(new ArrayList<>());
when(mockParserService.parseRawInput(anyString())).thenReturn(testNode);
when(mockParserService.retrieveStatements(testNode)).thenReturn(new ArrayList<>());
final boolean successfulTestDrive = parserService.parseUserInput("");
@@ -1,16 +0,0 @@
package edu.msudenver.tsp.services.scoring;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import static org.junit.Assert.assertEquals;
@RunWith(MockitoJUnitRunner.class)
public class TheoremScoringServiceTest {
@Test
public void test() {
assertEquals(3,3);
}
}