Procházet zdrojové kódy

updated class names, wrote tests for topiccreatorservice, added more spring annotations

William Simkins před 6 roky
rodič
revize
1cbd5f2c38
25 změnil soubory, kde provedl 256 přidání a 118 odebrání
  1. 13
    0
      pom.xml
  2. 8
    1
      src/main/java/com/tyler/motivateme/MainTopicsPage.java
  3. 5
    0
      src/main/java/com/tyler/motivateme/TopicInfoPage.java
  4. 13
    0
      src/main/java/com/tyler/motivateme/controller/MainTopicsPageController.java
  5. 0
    24
      src/main/java/com/tyler/motivateme/controller/NewTopicCreatorController.java
  6. 0
    13
      src/main/java/com/tyler/motivateme/controller/TestController1.java
  7. 23
    0
      src/main/java/com/tyler/motivateme/controller/TopicCreatorController.java
  8. 7
    2
      src/main/java/com/tyler/motivateme/controller/TopicInfoPageController.java
  9. 0
    14
      src/main/java/com/tyler/motivateme/model/NewTopicCreator.java
  10. 0
    18
      src/main/java/com/tyler/motivateme/model/NewTopicCreatorService.java
  11. 34
    0
      src/main/java/com/tyler/motivateme/model/Topic.java
  12. 47
    0
      src/main/java/com/tyler/motivateme/model/TopicCreatorService.java
  13. 9
    0
      src/main/java/com/tyler/motivateme/repository/TopicRepository.java
  14. 0
    17
      src/test/java/Model/NewAccountCreatorTest.java
  15. 0
    19
      src/test/java/Model/NewTopicCreatorTest.java
  16. 2
    1
      src/test/java/View/ForumTest.java
  17. 2
    1
      src/test/java/View/InboxTest.java
  18. 2
    1
      src/test/java/View/MainTopicsPageTest.java
  19. 2
    1
      src/test/java/View/TopicInfoPageTest.java
  20. 3
    2
      src/test/java/controller/CommentControllerTest.java
  21. 3
    2
      src/test/java/controller/MessageControllerTest.java
  22. 3
    2
      src/test/java/model/ConsoleTest.java
  23. 64
    0
      src/test/java/model/TopicCreatorServiceTest.java
  24. 12
    0
      src/test/java/repository/TopicRepositoryTest.java
  25. 4
    0
      src/test/java/repository/UserRepositoryTest.java

+ 13
- 0
pom.xml Zobrazit soubor

@@ -52,6 +52,19 @@
52 52
             <artifactId>spring-boot-starter-test</artifactId>
53 53
             <scope>test</scope>
54 54
         </dependency>
55
+
56
+        <dependency>
57
+            <groupId>com.h2database</groupId>
58
+            <artifactId>h2</artifactId>
59
+            <scope>test</scope>
60
+            <version>1.4.194</version>
61
+        </dependency>
62
+
63
+        <dependency>
64
+            <groupId>net.anthavio.disquo</groupId>
65
+            <artifactId>disquo-api</artifactId>
66
+            <version>1.0.2</version>
67
+        </dependency>
55 68
     </dependencies>
56 69
 
57 70
     <build>

+ 8
- 1
src/main/java/com/tyler/motivateme/MainTopicsPage.java Zobrazit soubor

@@ -1,12 +1,19 @@
1 1
 package com.tyler.motivateme;
2 2
 
3
+import com.tyler.motivateme.model.Topic;
4
+import org.springframework.context.annotation.Bean;
5
+import org.springframework.stereotype.Service;
6
+
3 7
 import java.util.ArrayList;
4 8
 import java.util.List;
5 9
 
10
+@Service
6 11
 public class MainTopicsPage {
7
-    List<String> topicsList;
12
+    List<Topic> topicsList;
8 13
 
9 14
     public MainTopicsPage(){
10 15
         this.topicsList = new ArrayList<>();
11 16
     }
17
+
18
+
12 19
 }

+ 5
- 0
src/main/java/com/tyler/motivateme/TopicInfoPage.java Zobrazit soubor

@@ -1,7 +1,12 @@
1 1
 package com.tyler.motivateme;
2 2
 
3
+import org.springframework.stereotype.Service;
4
+
5
+@Service
3 6
 public class TopicInfoPage{
4 7
 
8
+    public String getTopicName() {return null;}
9
+
5 10
     public String getDescription() {
6 11
         return null;
7 12
     }

+ 13
- 0
src/main/java/com/tyler/motivateme/controller/MainTopicsPageController.java Zobrazit soubor

@@ -0,0 +1,13 @@
1
+package com.tyler.motivateme.controller;
2
+
3
+import com.tyler.motivateme.MainTopicsPage;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.web.bind.annotation.RequestMapping;
6
+import org.springframework.web.bind.annotation.RestController;
7
+
8
+@RestController
9
+@RequestMapping("/MainTopics")
10
+public class MainTopicsPageController {
11
+    @Autowired
12
+    MainTopicsPage mainTopicsPage;
13
+}

+ 0
- 24
src/main/java/com/tyler/motivateme/controller/NewTopicCreatorController.java Zobrazit soubor

@@ -1,24 +0,0 @@
1
-package com.tyler.motivateme.controller;
2
-
3
-import org.springframework.web.bind.annotation.RequestMapping;
4
-import org.springframework.web.bind.annotation.RestController;
5
-
6
-@RestController
7
-public class NewTopicCreatorController {
8
-
9
-//    @Autowired
10
-//    private NewTopicCreatorService newTopicCreatorService;
11
-//
12
-//    @RequestMapping(path="/topics")
13
-//    public List<Topic> allTopics() {
14
-//
15
-//        return newTopicCreatorService.allTopics();
16
-//    }
17
-
18
-    @RequestMapping(value="/api/topics")
19
-    public String what(){
20
-        return "topic";
21
-    }
22
-
23
-
24
-}

+ 0
- 13
src/main/java/com/tyler/motivateme/controller/TestController1.java Zobrazit soubor

@@ -1,13 +0,0 @@
1
-package com.tyler.motivateme.controller;
2
-
3
-import org.springframework.web.bind.annotation.GetMapping;
4
-import org.springframework.web.bind.annotation.RestController;
5
-
6
-@RestController
7
-public class TestController1 {
8
-
9
-    @GetMapping(value = "/hello")
10
-    public String hello(){
11
-        return "world";
12
-    }
13
-}

+ 23
- 0
src/main/java/com/tyler/motivateme/controller/TopicCreatorController.java Zobrazit soubor

@@ -0,0 +1,23 @@
1
+package com.tyler.motivateme.controller;
2
+
3
+import com.tyler.motivateme.model.TopicCreatorService;
4
+import com.tyler.motivateme.model.Topic;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.web.bind.annotation.RequestMapping;
7
+import org.springframework.web.bind.annotation.RestController;
8
+
9
+import java.util.List;
10
+
11
+@RestController
12
+@RequestMapping("/topics")
13
+public class TopicCreatorController {
14
+
15
+    @Autowired
16
+    private TopicCreatorService topicCreatorService;
17
+
18
+    public List<Topic> allTopics() {
19
+
20
+        return topicCreatorService.allTopics();
21
+    }
22
+
23
+}

src/main/java/com/tyler/motivateme/controller/TopicsController.java → src/main/java/com/tyler/motivateme/controller/TopicInfoPageController.java Zobrazit soubor

@@ -1,11 +1,16 @@
1 1
 package com.tyler.motivateme.controller;
2 2
 
3
+import com.tyler.motivateme.MainTopicsPage;
4
+import org.springframework.beans.factory.annotation.Autowired;
3 5
 import org.springframework.web.bind.annotation.RequestMapping;
4 6
 import org.springframework.web.bind.annotation.RestController;
5 7
 
6 8
 @RestController
7
-@RequestMapping("/mytopics")
8
-public class TopicsController {
9
+@RequestMapping("/TopicInfo")
10
+public class TopicInfoPageController {
11
+
12
+    @Autowired
13
+    private MainTopicsPage mainTopicsPage;
9 14
 
10 15
     public String getDescription() {return null;}
11 16
     public String getAdviceAndStrategies() {return null;}

+ 0
- 14
src/main/java/com/tyler/motivateme/model/NewTopicCreator.java Zobrazit soubor

@@ -1,14 +0,0 @@
1
-package com.tyler.motivateme.model;
2
-
3
-
4
-public class NewTopicCreator{
5
-
6
-    public String getDescription() {
7
-
8
-        return null;
9
-    }
10
-
11
-    public String getAdviceAndStrategies() {
12
-        return null;
13
-    }
14
-}

+ 0
- 18
src/main/java/com/tyler/motivateme/model/NewTopicCreatorService.java Zobrazit soubor

@@ -1,18 +0,0 @@
1
-package com.tyler.motivateme.model;
2
-
3
-import org.springframework.stereotype.Service;
4
-
5
-import java.util.ArrayList;
6
-import java.util.Arrays;
7
-import java.util.List;
8
-
9
-@Service
10
-public class NewTopicCreatorService {
11
-
12
-    private List<Topic> topics = new ArrayList<Topic>(Arrays.asList(new Topic(1, "Quit drinking"), new Topic(2, "Quit Smoking"), new Topic(3, "Eat healthier")));
13
-
14
-    public List<Topic> allTopics() {
15
-
16
-        return topics;
17
-    }
18
-}

+ 34
- 0
src/main/java/com/tyler/motivateme/model/Topic.java Zobrazit soubor

@@ -1,18 +1,27 @@
1 1
 package com.tyler.motivateme.model;
2 2
 
3
+import javax.persistence.Entity;
3 4
 import javax.persistence.GeneratedValue;
4 5
 import javax.persistence.GenerationType;
5 6
 import javax.persistence.Id;
7
+import java.util.Objects;
6 8
 
9
+@Entity
7 10
 public class Topic {
8 11
     @Id
9 12
     @GeneratedValue(strategy = GenerationType.AUTO)
10 13
     private int id;
11 14
     private String name;
15
+    private String description;
16
+    private String adviceAndStrategies;
17
+
12 18
 
13 19
     public Topic(int id, String name) {
14 20
         this.id = id;
15 21
         this.name = name;
22
+        this.description = description;
23
+
24
+        this.adviceAndStrategies = adviceAndStrategies;
16 25
     }
17 26
 
18 27
     public Topic(){};
@@ -32,4 +41,29 @@ public class Topic {
32 41
     public void setName(String name) {
33 42
         this.name = name;
34 43
     }
44
+
45
+    public String getDescription() { return description; }
46
+
47
+    public void setDescription(String description) { this.description = description; }
48
+
49
+    public String getAdviceAndStrategies() { return adviceAndStrategies; }
50
+
51
+    public void setAdviceAndStrategies(String adviceAndStrategies) { this.adviceAndStrategies = adviceAndStrategies; }
52
+
53
+    @Override
54
+    public boolean equals(Object o) {
55
+        if (this == o) return true;
56
+        if (o == null || getClass() != o.getClass()) return false;
57
+        Topic topic = (Topic) o;
58
+        return id == topic.id &&
59
+                Objects.equals(name, topic.name) &&
60
+                Objects.equals(description, topic.description) &&
61
+                Objects.equals(adviceAndStrategies, topic.adviceAndStrategies);
62
+    }
63
+
64
+    @Override
65
+    public int hashCode() {
66
+
67
+        return Objects.hash(id, name, description, adviceAndStrategies);
68
+    }
35 69
 }

+ 47
- 0
src/main/java/com/tyler/motivateme/model/TopicCreatorService.java Zobrazit soubor

@@ -0,0 +1,47 @@
1
+package com.tyler.motivateme.model;
2
+
3
+import org.springframework.stereotype.Service;
4
+
5
+import java.util.ArrayList;
6
+import java.util.Arrays;
7
+import java.util.List;
8
+
9
+@Service
10
+public class TopicCreatorService {
11
+
12
+    private List<Topic> topics;
13
+    private String description;
14
+    private String adviceAndStrategies;
15
+
16
+    public TopicCreatorService(){
17
+        this.topics = topics = new ArrayList<Topic>(Arrays.asList(new Topic(1, "Quit drinking"), new Topic(2, "Quit Smoking"), new Topic(3, "Eat healthier")));
18
+        this.description = description;
19
+        this.adviceAndStrategies = adviceAndStrategies;
20
+    }
21
+
22
+    public List<Topic> allTopics() {
23
+
24
+        return topics;
25
+    }
26
+
27
+    public void setDescription(String description) {
28
+        this.description = description;
29
+    }
30
+
31
+    public void setAdviceAndStrategies(String adviceAndStrategies) {
32
+        this.adviceAndStrategies = adviceAndStrategies;
33
+    }
34
+
35
+    public String getDescription() {
36
+
37
+        return description;
38
+    }
39
+
40
+    public String getAdviceAndStrategies() {
41
+        return adviceAndStrategies;
42
+    }
43
+
44
+    public void add(Topic topic) {
45
+        topics.add(topic);
46
+    }
47
+}

+ 9
- 0
src/main/java/com/tyler/motivateme/repository/TopicRepository.java Zobrazit soubor

@@ -0,0 +1,9 @@
1
+package com.tyler.motivateme.repository;
2
+
3
+import com.tyler.motivateme.model.Topic;
4
+import org.springframework.data.repository.CrudRepository;
5
+import org.springframework.stereotype.Repository;
6
+
7
+@Repository
8
+public interface TopicRepository extends CrudRepository<Topic, Integer> {
9
+}

+ 0
- 17
src/test/java/Model/NewAccountCreatorTest.java Zobrazit soubor

@@ -1,17 +0,0 @@
1
-package Model;
2
-
3
-import org.junit.Test;
4
-import org.junit.runner.RunWith;
5
-import org.springframework.boot.test.context.SpringBootTest;
6
-import org.springframework.test.context.junit4.SpringRunner;
7
-
8
-@RunWith(SpringRunner.class)
9
-@SpringBootTest
10
-public class NewAccountCreatorTest {
11
-
12
-    @Test
13
-    public void testCreateUser() {
14
-
15
-    }
16
-
17
-}

+ 0
- 19
src/test/java/Model/NewTopicCreatorTest.java Zobrazit soubor

@@ -1,19 +0,0 @@
1
-package Model;
2
-
3
-import org.junit.Test;
4
-import org.junit.runner.RunWith;
5
-import org.springframework.boot.test.context.SpringBootTest;
6
-import org.springframework.test.context.junit4.SpringRunner;
7
-
8
-@RunWith(SpringRunner.class)
9
-@SpringBootTest
10
-public class NewTopicCreatorTest {
11
-
12
-    @Test
13
-    public void getDescription() {
14
-    }
15
-
16
-    @Test
17
-    public void getAdviceAndStrategies() {
18
-    }
19
-}

+ 2
- 1
src/test/java/View/ForumTest.java Zobrazit soubor

@@ -3,10 +3,11 @@ package View;
3 3
 import org.junit.Test;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.ContextConfiguration;
6 7
 import org.springframework.test.context.junit4.SpringRunner;
7 8
 
8 9
 @RunWith(SpringRunner.class)
9
-@SpringBootTest
10
+@ContextConfiguration
10 11
 public class ForumTest {
11 12
 
12 13
     @Test

+ 2
- 1
src/test/java/View/InboxTest.java Zobrazit soubor

@@ -3,10 +3,11 @@ package View;
3 3
 import org.junit.Test;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.ContextConfiguration;
6 7
 import org.springframework.test.context.junit4.SpringRunner;
7 8
 
8 9
 @RunWith(SpringRunner.class)
9
-@SpringBootTest
10
+@ContextConfiguration
10 11
 public class InboxTest {
11 12
 
12 13
     @Test

+ 2
- 1
src/test/java/View/MainTopicsPageTest.java Zobrazit soubor

@@ -3,10 +3,11 @@ package View;
3 3
 import org.junit.Test;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.ContextConfiguration;
6 7
 import org.springframework.test.context.junit4.SpringRunner;
7 8
 
8 9
 @RunWith(SpringRunner.class)
9
-@SpringBootTest
10
+@ContextConfiguration
10 11
 public class MainTopicsPageTest {
11 12
 
12 13
     @Test

+ 2
- 1
src/test/java/View/TopicInfoPageTest.java Zobrazit soubor

@@ -3,10 +3,11 @@ package View;
3 3
 import org.junit.Test;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.ContextConfiguration;
6 7
 import org.springframework.test.context.junit4.SpringRunner;
7 8
 
8 9
 @RunWith(SpringRunner.class)
9
-@SpringBootTest
10
+@ContextConfiguration
10 11
 public class TopicInfoPageTest {
11 12
 
12 13
     @Test

src/test/java/Controllers/CommentControllerTest.java → src/test/java/controller/CommentControllerTest.java Zobrazit soubor

@@ -1,12 +1,13 @@
1
-package Controllers;
1
+package controller;
2 2
 
3 3
 import org.junit.Test;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.ContextConfiguration;
6 7
 import org.springframework.test.context.junit4.SpringRunner;
7 8
 
8 9
 @RunWith(SpringRunner.class)
9
-@SpringBootTest
10
+@ContextConfiguration
10 11
 public class CommentControllerTest {
11 12
 
12 13
     @Test

src/test/java/Controllers/MessageControllerTest.java → src/test/java/controller/MessageControllerTest.java Zobrazit soubor

@@ -1,13 +1,14 @@
1
-package Controllers;
1
+package controller;
2 2
 
3 3
 import org.junit.Test;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.ContextConfiguration;
6 7
 import org.springframework.test.context.junit4.SpringRunner;
7 8
 
8 9
 
9 10
 @RunWith(SpringRunner.class)
10
-@SpringBootTest
11
+@ContextConfiguration
11 12
 public class MessageControllerTest {
12 13
 
13 14
     @Test

src/test/java/Model/ConsoleTest.java → src/test/java/model/ConsoleTest.java Zobrazit soubor

@@ -1,13 +1,14 @@
1
-package Model;
1
+package model;
2 2
 
3 3
 import org.junit.Test;
4 4
 import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6
+import org.springframework.test.context.ContextConfiguration;
6 7
 import org.springframework.test.context.junit4.SpringRunner;
7 8
 
8 9
 
9 10
 @RunWith(SpringRunner.class)
10
-@SpringBootTest
11
+@ContextConfiguration
11 12
 public class ConsoleTest {
12 13
 
13 14
     @Test

+ 64
- 0
src/test/java/model/TopicCreatorServiceTest.java Zobrazit soubor

@@ -0,0 +1,64 @@
1
+package model;
2
+
3
+import com.tyler.motivateme.model.Topic;
4
+import com.tyler.motivateme.model.TopicCreatorService;
5
+import org.junit.Test;
6
+import org.junit.runner.RunWith;
7
+import org.springframework.test.context.ContextConfiguration;
8
+import org.springframework.test.context.junit4.SpringRunner;
9
+
10
+import java.util.ArrayList;
11
+import java.util.Arrays;
12
+import java.util.List;
13
+
14
+import static org.junit.Assert.assertEquals;
15
+import static org.junit.Assert.assertTrue;
16
+
17
+@RunWith(SpringRunner.class)
18
+@ContextConfiguration
19
+public class TopicCreatorServiceTest {
20
+
21
+    TopicCreatorService tcs = new TopicCreatorService();
22
+
23
+    @Test
24
+    public void testGetDescription() {
25
+        String expected = "This is a description of the topic";
26
+        tcs.setDescription(expected);
27
+        String actual = tcs.getDescription();
28
+        assertEquals(expected, actual);
29
+    }
30
+
31
+    @Test
32
+    public void testGetAdviceAndStrategies() {
33
+        String expected = "This is the advice and strategies section of the topic";
34
+        tcs.setAdviceAndStrategies(expected);
35
+        String actual = tcs.getAdviceAndStrategies();
36
+        assertEquals(expected, actual);
37
+    }
38
+
39
+    @Test
40
+    public void testAllTopics_AreInList(){
41
+        List expected = new ArrayList<>(Arrays.asList(new Topic(1, "Quit drinking"), new Topic(2, "Quit Smoking"), new Topic(3, "Eat healthier")));
42
+        List actual = tcs.allTopics();
43
+        assertEquals(expected, actual);
44
+    }
45
+
46
+
47
+    @Test
48
+    public void testConstruction(){
49
+        List<Topic> topics = tcs.allTopics();
50
+
51
+        assertEquals(topics.size(), 3);
52
+        assertTrue(topics.contains(new Topic(1, "Quit drinking")));
53
+    }
54
+
55
+    @Test
56
+    public void testAddTopics_toAllTopics(){
57
+        Topic topic = new Topic(4, "working out");
58
+        tcs.add(topic);
59
+
60
+        List<Topic> topics = tcs.allTopics();
61
+
62
+        assertTrue(topics.contains(topic));
63
+    }
64
+}

+ 12
- 0
src/test/java/repository/TopicRepositoryTest.java Zobrazit soubor

@@ -0,0 +1,12 @@
1
+package repository;
2
+
3
+import org.junit.Test;
4
+import org.junit.runner.RunWith;
5
+import org.springframework.test.context.ContextConfiguration;
6
+import org.springframework.test.context.junit4.SpringRunner;
7
+
8
+@RunWith(SpringRunner.class)
9
+@ContextConfiguration
10
+public class TopicRepositoryTest {
11
+
12
+}

+ 4
- 0
src/test/java/repository/UserRepositoryTest.java Zobrazit soubor

@@ -0,0 +1,4 @@
1
+package repository;
2
+
3
+public class UserRepositoryTest {
4
+}