PAN-15 Created initial UserService implementation and initial integration tests
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
public class ServicesTestConfig {
|
||||
|
||||
@Bean
|
||||
@Autowired
|
||||
public UserService userService(final RestService restService) {
|
||||
return new UserService(restService);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import edu.msudenver.tsp.services.dto.Account;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = ServicesTestConfig.class)
|
||||
@TestPropertySource("classpath:test.properties")
|
||||
public class UserServiceIntegrationTest {
|
||||
@Autowired
|
||||
@Qualifier("userService")
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void testCreateNewUser() throws ParseException {
|
||||
final Account testAccount = new Account();
|
||||
testAccount.setUsername("test user");
|
||||
testAccount.setPassword("test password");
|
||||
testAccount.setAdministratorStatus(false);
|
||||
testAccount.setLastLogin(new Date());
|
||||
|
||||
final Optional<Account> testCreatedAccount = userService.createNewAccount(testAccount);
|
||||
|
||||
assertTrue(testCreatedAccount.isPresent());
|
||||
final Account returnedAccount = testCreatedAccount.get();
|
||||
Assert.assertEquals("test user", returnedAccount.getUsername());
|
||||
Assert.assertEquals("test password", returnedAccount.getPassword());
|
||||
Assert.assertEquals(false, returnedAccount.isAdministratorStatus());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
persistence.api.connection.timeout.milliseconds=5000
|
||||
persistence.api.socket.timeout.milliseconds=10000
|
||||
persistence.api.base.url=http://localhost:8090/
|
||||
@@ -0,0 +1,14 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration(exclude = {DevToolsDataSourceAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class,
|
||||
DataSourceAutoConfiguration.class})
|
||||
public class ServiceConfig {
|
||||
}
|
||||
@@ -34,8 +34,8 @@ public class UserService {
|
||||
|
||||
try {
|
||||
final TypeToken<Account> typeToken = new TypeToken<Account>() {};
|
||||
final Optional<Account> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "/accounts/",
|
||||
new GsonBuilder().create().toJson(account),
|
||||
final Optional<Account> persistenceApiResponse = restService.post(persistenceApiBaseUrl + "accounts/",
|
||||
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create().toJson(account),
|
||||
typeToken,
|
||||
connectionTimeoutMilliseconds,
|
||||
socketTimeoutMilliseconds);
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package edu.msudenver.tsp.services.dto;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import edu.msudenver.tsp.persistence.dto.AccountDto;
|
||||
import lombok.Data;
|
||||
|
||||
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;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class Account extends BaseDto implements Serializable {
|
||||
@NotBlank(groups = AccountDto.Insert.class, message = "A username must be specified") @Size(max = 50) private String username;
|
||||
@NotBlank(groups = AccountDto.Insert.class, message = "A password must be specified") @Size(max = 256) private String password;
|
||||
@Size(max = 50) private String username;
|
||||
@Size(max = 256) private String password;
|
||||
@NotNull @SerializedName("administrator_status") private boolean administratorStatus;
|
||||
@Temporal(TemporalType.DATE) @SerializedName("last_login") private Date lastLogin;
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
package edu.msudenver.tsp.services.parser;
|
||||
|
||||
import edu.msudenver.tsp.persistence.controller.DefinitionController;
|
||||
import edu.msudenver.tsp.persistence.controller.NotationController;
|
||||
import edu.msudenver.tsp.persistence.controller.ProofController;
|
||||
import edu.msudenver.tsp.persistence.controller.TheoremController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -12,21 +7,8 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
class ParserService {
|
||||
private final DefinitionController definitionController;
|
||||
private final TheoremController theoremController;
|
||||
private final NotationController notationController;
|
||||
private final ProofController proofController;
|
||||
private Node root;
|
||||
|
||||
@Autowired
|
||||
public ParserService(final DefinitionController definitionController, final TheoremController theoremController,
|
||||
final NotationController notationController, final ProofController proofController) {
|
||||
this.definitionController = definitionController;
|
||||
this.theoremController = theoremController;
|
||||
this.notationController = notationController;
|
||||
this.proofController = proofController;
|
||||
}
|
||||
|
||||
public boolean parseUserInput(final String userInput)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
persistence.api.connection.timeout.milliseconds = 5000
|
||||
persistence.api.socket.timeout.milliseconds = 10000
|
||||
persistence.api.base.url = http://localhost:8090/
|
||||
persistence.api.connection.timeout.milliseconds=5000
|
||||
persistence.api.socket.timeout.milliseconds=10000
|
||||
persistence.api.base.url=http://localhost:8090/
|
||||
Reference in New Issue
Block a user