PAN-15 Fixed unit tests
This commit is contained in:
+5
-1
@@ -1,3 +1,4 @@
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@@ -70,7 +71,6 @@ subprojects {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||
|
||||
}
|
||||
|
||||
test {
|
||||
@@ -107,7 +107,11 @@ dependencies {
|
||||
compile 'org.slf4j:slf4j-api:1.7.22'
|
||||
compile "joda-time:joda-time:2.2"
|
||||
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.5.RELEASE'
|
||||
compile('org.springframework.boot:spring-boot-starter-web','org.apache.tomcat.embed:tomcat-embed-jasper'
|
||||
,'javax.servlet:jstl')
|
||||
|
||||
testCompile 'javax.el:javax.el-api:3.0.0'
|
||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.3.RELEASE'
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||
testCompile('org.mockito:mockito-core:1.10.19') {exclude(group: 'org.hamcrest')}
|
||||
|
||||
@@ -56,19 +56,21 @@ public class UserService {
|
||||
}
|
||||
}
|
||||
|
||||
public Optional<Account> updatePassword(final Account account , final String password){
|
||||
|
||||
if(account ==null){
|
||||
LOG.error("user not exist, returning{}");
|
||||
public Optional<Account> updateAccount(final Account account) {
|
||||
if (account == null) {
|
||||
LOG.error("User does not exist, returning {}");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final Integer id = account.getId();
|
||||
account.setPassword(password);
|
||||
if (account.getId() == 0) {
|
||||
LOG.error("No user ID specified! Returning {}");
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
final int id = account.getId();
|
||||
final Instant start = Instant.now();
|
||||
|
||||
try{
|
||||
final String auth = "";
|
||||
try {
|
||||
final TypeToken<Account> typeToken = new TypeToken<Account>(){};
|
||||
final Optional<Account> persistenceApiResponse = restService.patch(persistenceApiBaseUrl + "accounts/" + id,
|
||||
new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").create().toJson(account),
|
||||
@@ -79,15 +81,15 @@ public class UserService {
|
||||
if (persistenceApiResponse.isPresent()) {
|
||||
LOG.info("Returning {}", persistenceApiResponse.get());
|
||||
} else {
|
||||
LOG.info("Unable to update password for account {}",account.toString());
|
||||
LOG.info("Unable to update user {} with id", account.getId());
|
||||
}
|
||||
|
||||
return persistenceApiResponse;
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Error updating account {}", e);
|
||||
LOG.error("Error updating user {}", e);
|
||||
return Optional.empty();
|
||||
} finally {
|
||||
LOG.info("Update account request took {} ms", Duration.between(start, Instant.now()).toMillis());
|
||||
LOG.info("Update user request took {} ms", Duration.between(start, Instant.now()).toMillis());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package edu.msudenver.tsp.services;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import edu.msudenver.tsp.services.dto.Account;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UserServiceTest {
|
||||
@Mock
|
||||
private RestService restService;
|
||||
@InjectMocks
|
||||
private UserService userService;
|
||||
|
||||
@Test
|
||||
public void testCreateNewAccount() throws ParseException {
|
||||
|
||||
final Account account = new Account();
|
||||
account.setUsername("Test username");
|
||||
account.setPassword("test password");
|
||||
account.setAdministratorStatus(false);
|
||||
account.setLastLogin(new Date());
|
||||
|
||||
when(restService.post(anyString(), anyString(), any(TypeToken.class), anyInt(), anyInt()))
|
||||
.thenReturn(Optional.of(account));
|
||||
|
||||
final Optional<Account> response = userService.createNewAccount(account);
|
||||
|
||||
assertTrue(response.isPresent());
|
||||
assertEquals(account, response.get());
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,9 @@
|
||||
package edu.msudenver.tsp.website;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
@@ -17,17 +11,8 @@ public class Application {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner commandLineRunner(final ApplicationContext ctx) {
|
||||
return args -> {
|
||||
|
||||
LOG.info("Beans provided by Spring Boot:");
|
||||
|
||||
final String[] beanNames = ctx.getBeanDefinitionNames();
|
||||
Arrays.sort(beanNames);
|
||||
for (final String beanName : beanNames) {
|
||||
LOG.info(beanName);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,21 @@
|
||||
Time: 8:03 PM
|
||||
To change this template use File | Settings | File Templates.
|
||||
--%>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
|
||||
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>$Title$</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Theroem Prover</title>
|
||||
</head>
|
||||
<body>
|
||||
$END$
|
||||
<div>
|
||||
<div>
|
||||
<h1>Theorem Prover</h1>
|
||||
<h2>Hello! ${message}</h2>
|
||||
|
||||
Click on this <strong><a href="next">link</a></strong> to visit theorem entering page.
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user