diff --git a/build.gradle b/build.gradle index cc21aa1..e00bb1b 100644 --- a/build.gradle +++ b/build.gradle @@ -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')} diff --git a/services/src/main/java/edu/msudenver/tsp/services/UserService.java b/services/src/main/java/edu/msudenver/tsp/services/UserService.java index ffb78a5..d717e2b 100644 --- a/services/src/main/java/edu/msudenver/tsp/services/UserService.java +++ b/services/src/main/java/edu/msudenver/tsp/services/UserService.java @@ -56,19 +56,21 @@ public class UserService { } } - public Optional updatePassword(final Account account , final String password){ - - if(account ==null){ - LOG.error("user not exist, returning{}"); + public Optional 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 typeToken = new TypeToken(){}; final Optional 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()); } } diff --git a/services/src/test/java/edu/msudenver/tsp/services/UserServiceTest.java b/services/src/test/java/edu/msudenver/tsp/services/UserServiceTest.java new file mode 100644 index 0000000..52379b0 --- /dev/null +++ b/services/src/test/java/edu/msudenver/tsp/services/UserServiceTest.java @@ -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 response = userService.createNewAccount(account); + + assertTrue(response.isPresent()); + assertEquals(account, response.get()); + } +} \ No newline at end of file diff --git a/src/main/java/edu/msudenver/tsp/website/Application.java b/src/main/java/edu/msudenver/tsp/website/Application.java index c8f0854..3339429 100644 --- a/src/main/java/edu/msudenver/tsp/website/Application.java +++ b/src/main/java/edu/msudenver/tsp/website/Application.java @@ -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); - } - }; - } + + } diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index f8d618c..6417074 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -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" %> + - $Title$ + + Theroem Prover - $END$ +
+
+

Theorem Prover

+

Hello! ${message}

+ + Click on this link to visit theorem entering page. +
+