unit tests

This commit is contained in:
Szakalakamaka
2020-10-09 16:56:48 +02:00
parent 2c5cddb93e
commit 76cab9630f
11 changed files with 307 additions and 143 deletions

129
.idea/workspace.xml generated
View File

@@ -23,10 +23,13 @@
</component>
<component name="ChangeListManager">
<list default="true" id="458cde88-df3d-44bc-9d57-a33823e2f1a6" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/test/java/com/release11/klaus/service/EtrackServiceImplTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/release11/klaus/controller/KlausController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/release11/klaus/controller/KlausController.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/com/release11/klaus/repository/LogsRepository.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/resources/data-access.properties" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/data-access.properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/test-classes/com/release11/klaus/controller/EventControllerTest.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/test-classes/com/release11/klaus/controller/EventControllerTest.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/test-classes/com/release11/klaus/controller/KlausControllerTest.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/test-classes/com/release11/klaus/controller/KlausControllerTest.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/com/release11/klaus/service/KlausServiceImplTest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/com/release11/klaus/service/KlausServiceImplTest.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/com/release11/klaus/controller/KlausController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/release11/klaus/controller/KlausController.class" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -84,6 +87,7 @@
</component>
<component name="RecentsManager">
<key name="CreateTestDialog.RecentsKey">
<recent name="com.release11.klaus.service" />
<recent name="com.release11.klaus.controller" />
</key>
<key name="CreateTestDialog.Recents.Supers">
@@ -111,7 +115,7 @@
<recent name="com.release11.klaus.service" />
</key>
</component>
<component name="RunManager" selected="Application.KlausApplication">
<component name="RunManager" selected="JUnit.KlausServiceImplTest">
<configuration name="KlausApplication" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<envs>
<env name="-Dspring.profiles.active" value="test" />
@@ -128,16 +132,16 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="EventControllerTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="EtrackServiceImplTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Klaus" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.release11.klaus.controller.*" />
<option name="PATTERN" value="com.release11.klaus.service.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="com.release11.klaus.controller" />
<option name="MAIN_CLASS_NAME" value="com.release11.klaus.controller.EventControllerTest" />
<option name="PACKAGE_NAME" value="com.release11.klaus.service" />
<option name="MAIN_CLASS_NAME" value="com.release11.klaus.service.EtrackServiceImplTest" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
@@ -173,18 +177,17 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="KlausMvcControllerTest.addHeader" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<configuration name="KlausServiceImplTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="Klaus" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.release11.klaus.controller.*" />
<option name="PATTERN" value="com.release11.klaus.service.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="com.release11.klaus.controller" />
<option name="MAIN_CLASS_NAME" value="com.release11.klaus.controller.KlausMvcControllerTest" />
<option name="METHOD_NAME" value="addHeader" />
<option name="TEST_OBJECT" value="method" />
<option name="PACKAGE_NAME" value="com.release11.klaus.service" />
<option name="MAIN_CLASS_NAME" value="com.release11.klaus.service.KlausServiceImplTest" />
<option name="TEST_OBJECT" value="class" />
<method v="2">
<option name="Make" enabled="true" />
</method>
@@ -238,18 +241,18 @@
</configuration>
<list>
<item itemvalue="Application.KlausApplication" />
<item itemvalue="JUnit.EventControllerTest" />
<item itemvalue="JUnit.KlausMvcControllerTest" />
<item itemvalue="JUnit.KlausMvcControllerTest.addHeader" />
<item itemvalue="JUnit.KlausControllerTest" />
<item itemvalue="JUnit.EtrackServiceImplTest" />
<item itemvalue="JUnit.KlausServiceImplTest" />
</list>
<recent_temporary>
<list>
<item itemvalue="JUnit.KlausServiceImplTest" />
<item itemvalue="JUnit.EtrackServiceImplTest" />
<item itemvalue="Application.KlausApplication" />
<item itemvalue="JUnit.KlausMvcControllerTest" />
<item itemvalue="JUnit.KlausControllerTest" />
<item itemvalue="JUnit.EventControllerTest" />
<item itemvalue="JUnit.KlausMvcControllerTest.addHeader" />
</list>
</recent_temporary>
</component>
@@ -265,13 +268,6 @@
<option name="presentableId" value="Default" />
<updated>1598862102028</updated>
</task>
<task id="LOCAL-00052" summary="testing jenkins docker">
<created>1601287668529</created>
<option name="number" value="00052" />
<option name="presentableId" value="LOCAL-00052" />
<option name="project" value="LOCAL" />
<updated>1601287668529</updated>
</task>
<task id="LOCAL-00053" summary="testing jenkins docker">
<created>1601294193991</created>
<option name="number" value="00053" />
@@ -608,7 +604,14 @@
<option name="project" value="LOCAL" />
<updated>1602140028044</updated>
</task>
<option name="localTasksCounter" value="101" />
<task id="LOCAL-00101" summary="switching docker network">
<created>1602145228592</created>
<option name="number" value="00101" />
<option name="presentableId" value="LOCAL-00101" />
<option name="project" value="LOCAL" />
<updated>1602145228592</updated>
</task>
<option name="localTasksCounter" value="102" />
<servers />
</component>
<component name="UnknownFeatures">
@@ -628,7 +631,6 @@
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="adding &quot;new message&quot; button" />
<MESSAGE value="etrack" />
<MESSAGE value="new buttons" />
<MESSAGE value="sorting" />
@@ -653,7 +655,8 @@
<MESSAGE value="adding new spring profiles" />
<MESSAGE value="changing module settings,&#10;adding unit testing for controllers" />
<MESSAGE value="cleaning" />
<option name="LAST_COMMIT_MESSAGE" value="cleaning" />
<MESSAGE value="switching docker network" />
<option name="LAST_COMMIT_MESSAGE" value="switching docker network" />
</component>
<component name="WindowStateProjectService">
<state x="904" y="236" key="#Notifications" timestamp="1600868491636">
@@ -690,62 +693,62 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="508" y="128" width="904" height="610" key="EnvironmentVariablesDialog/0.0.1536.824@0.0.1536.824" timestamp="1601384219062" />
<state x="549" y="167" key="FileChooserDialogImpl" timestamp="1602062761111">
<state x="549" y="167" key="FileChooserDialogImpl" timestamp="1602147205037">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="549" y="167" key="FileChooserDialogImpl/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602062761111" />
<state x="549" y="167" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1601990587478" />
<state width="1493" height="217" key="GridCell.Tab.0.bottom" timestamp="1602140137399">
<screen x="0" y="0" width="1536" height="824" />
<state x="549" y="167" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1602147205037" />
<state width="1877" height="276" key="GridCell.Tab.0.bottom" timestamp="1602253960877">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="239" key="GridCell.Tab.0.bottom/-1920.0.1536.832/0.0.1920.1040@0.0.1920.1040" timestamp="1600275797041" />
<state width="1493" height="261" key="GridCell.Tab.0.bottom/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075476021" />
<state width="1877" height="265" key="GridCell.Tab.0.bottom/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602101613148" />
<state width="1493" height="217" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1602140137399" />
<state width="1493" height="217" key="GridCell.Tab.0.center" timestamp="1602140137398">
<screen x="0" y="0" width="1536" height="824" />
<state width="1493" height="217" key="GridCell.Tab.0.bottom/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602249237084" />
<state width="1877" height="276" key="GridCell.Tab.0.bottom/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253960877" />
<state width="1493" height="217" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1602147432366" />
<state width="1877" height="276" key="GridCell.Tab.0.center" timestamp="1602253960876">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="239" key="GridCell.Tab.0.center/-1920.0.1536.832/0.0.1920.1040@0.0.1920.1040" timestamp="1600275797041" />
<state width="1493" height="261" key="GridCell.Tab.0.center/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075476021" />
<state width="1877" height="265" key="GridCell.Tab.0.center/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602101613147" />
<state width="1493" height="217" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1602140137398" />
<state width="1493" height="217" key="GridCell.Tab.0.left" timestamp="1602140137398">
<screen x="0" y="0" width="1536" height="824" />
<state width="1493" height="217" key="GridCell.Tab.0.center/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602249237084" />
<state width="1877" height="276" key="GridCell.Tab.0.center/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253960876" />
<state width="1493" height="217" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1602147432366" />
<state width="1877" height="276" key="GridCell.Tab.0.left" timestamp="1602253960875">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="239" key="GridCell.Tab.0.left/-1920.0.1536.832/0.0.1920.1040@0.0.1920.1040" timestamp="1600275797041" />
<state width="1493" height="261" key="GridCell.Tab.0.left/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075476020" />
<state width="1877" height="265" key="GridCell.Tab.0.left/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602101613146" />
<state width="1493" height="217" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1602140137398" />
<state width="1493" height="217" key="GridCell.Tab.0.right" timestamp="1602140137399">
<screen x="0" y="0" width="1536" height="824" />
<state width="1493" height="217" key="GridCell.Tab.0.left/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602249237084" />
<state width="1877" height="276" key="GridCell.Tab.0.left/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253960875" />
<state width="1493" height="217" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1602147432366" />
<state width="1877" height="276" key="GridCell.Tab.0.right" timestamp="1602253960877">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1877" height="239" key="GridCell.Tab.0.right/-1920.0.1536.832/0.0.1920.1040@0.0.1920.1040" timestamp="1600275797041" />
<state width="1493" height="261" key="GridCell.Tab.0.right/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075476021" />
<state width="1877" height="265" key="GridCell.Tab.0.right/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602101613147" />
<state width="1493" height="217" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1602140137399" />
<state width="1877" height="261" key="GridCell.Tab.1.bottom" timestamp="1602080974055">
<state width="1493" height="217" key="GridCell.Tab.0.right/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602249237084" />
<state width="1877" height="276" key="GridCell.Tab.0.right/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253960877" />
<state width="1493" height="217" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1602147432366" />
<state width="1877" height="261" key="GridCell.Tab.1.bottom" timestamp="1602253420337">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1493" height="261" key="GridCell.Tab.1.bottom/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075481186" />
<state width="1877" height="261" key="GridCell.Tab.1.bottom/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602080974055" />
<state width="1877" height="261" key="GridCell.Tab.1.bottom/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253420337" />
<state width="1493" height="261" key="GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824" timestamp="1600697207730" />
<state width="1877" height="261" key="GridCell.Tab.1.center" timestamp="1602080974055">
<state width="1877" height="261" key="GridCell.Tab.1.center" timestamp="1602253420336">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1493" height="261" key="GridCell.Tab.1.center/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075481185" />
<state width="1877" height="261" key="GridCell.Tab.1.center/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602080974055" />
<state width="1877" height="261" key="GridCell.Tab.1.center/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253420336" />
<state width="1493" height="261" key="GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824" timestamp="1600697207730" />
<state width="1877" height="261" key="GridCell.Tab.1.left" timestamp="1602080974055">
<state width="1877" height="261" key="GridCell.Tab.1.left" timestamp="1602253420336">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1493" height="261" key="GridCell.Tab.1.left/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075481185" />
<state width="1877" height="261" key="GridCell.Tab.1.left/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602080974055" />
<state width="1877" height="261" key="GridCell.Tab.1.left/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253420336" />
<state width="1493" height="261" key="GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824" timestamp="1600697207730" />
<state width="1877" height="261" key="GridCell.Tab.1.right" timestamp="1602080974055">
<state width="1877" height="261" key="GridCell.Tab.1.right" timestamp="1602253420337">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="1493" height="261" key="GridCell.Tab.1.right/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602075481185" />
<state width="1877" height="261" key="GridCell.Tab.1.right/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602080974055" />
<state width="1877" height="261" key="GridCell.Tab.1.right/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602253420337" />
<state width="1493" height="261" key="GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824" timestamp="1600697207730" />
<state x="299" y="67" key="Maven.ArtifactSearchDialog" timestamp="1598862685882">
<screen x="0" y="0" width="1536" height="824" />
@@ -765,25 +768,25 @@
</state>
<state x="277" y="57" key="SettingsEditor/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1600935670743" />
<state x="277" y="57" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1601975962923" />
<state x="361" y="145" key="Vcs.Push.Dialog.v2" timestamp="1602140029487">
<state x="361" y="145" key="Vcs.Push.Dialog.v2" timestamp="1602145235569">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="451" y="183" key="Vcs.Push.Dialog.v2/-1920.0.1536.832/0.0.1920.1040@0.0.1920.1040" timestamp="1600275760386" />
<state x="361" y="145" key="Vcs.Push.Dialog.v2/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1600350277680" />
<state x="2371" y="183" key="Vcs.Push.Dialog.v2/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602101594045" />
<state x="361" y="145" key="Vcs.Push.Dialog.v2/0.0.1536.824@0.0.1536.824" timestamp="1602140029487" />
<state x="361" y="145" key="Vcs.Push.Dialog.v2/0.0.1536.824@0.0.1536.824" timestamp="1602145235569" />
<state width="968" height="528" key="XDebugger.FullValuePopup" timestamp="1602076898344">
<screen x="1920" y="0" width="1920" height="1040" />
</state>
<state width="968" height="528" key="XDebugger.FullValuePopup/0.0.1536.824/1920.0.1920.1040@1920.0.1920.1040" timestamp="1602076898344" />
<state x="540" y="186" key="com.intellij.testIntegration.createTest.CreateTestDialog" timestamp="1602062880931">
<state x="540" y="186" key="com.intellij.testIntegration.createTest.CreateTestDialog" timestamp="1602239324911">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="540" y="186" key="com.intellij.testIntegration.createTest.CreateTestDialog/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602062880931" />
<state x="478" y="23" width="579" height="801" key="find.popup" timestamp="1602070770513">
<state x="540" y="186" key="com.intellij.testIntegration.createTest.CreateTestDialog/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602239324911" />
<state x="478" y="23" width="579" height="801" key="find.popup" timestamp="1602248839921">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="478" y="23" width="579" height="801" key="find.popup/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602070770513" />
<state x="478" y="23" width="579" height="801" key="find.popup/0.0.1536.824/1920.0.1920.1040@0.0.1536.824" timestamp="1602248839921" />
<state x="478" y="145" width="579" height="592" key="find.popup/0.0.1536.824@0.0.1536.824" timestamp="1599562452922" />
<state x="209" y="33" key="new project wizard" timestamp="1601969134275">
<screen x="0" y="0" width="1536" height="824" />

View File

@@ -39,8 +39,7 @@ public class KlausController {
@GetMapping(value = "klaus/v1/getAll/{clientUUID}")
public ResponseEntity<String> getAllMockedResponses(@PathVariable UUID clientUUID){
TrackingClient.setBusinessKeys(Map.of(BusinessKey.INTERFACE_NAME, "getAllMockedResponse",
BusinessKey.CLIENT_UUID, String.valueOf(clientUUID),
BusinessKey.MESSAGE_ID, "all"));
BusinessKey.CLIENT_UUID, String.valueOf(clientUUID)));
List<MockedMessageDto> mockedMessages = klausService.getAllMockedResponses(clientUUID);
return new ResponseEntity<>(mockedMessages.toString(), HttpStatus.OK);
}

View File

@@ -1,12 +0,0 @@
package com.release11.klaus.repository;
import com.release11.klaus.utilis.BusinessKey;
import org.springframework.stereotype.Repository;
import java.time.ZonedDateTime;
import java.util.List;
@Repository
public interface LogsRepository {
String getLogsByBusinessKeys(List<BusinessKey> businessKeys, ZonedDateTime zonedDateTime);
}

View File

@@ -1,2 +1,2 @@
redis.host = redis
redis.host = localhost
redis.port = 6379

View File

@@ -0,0 +1,24 @@
package com.release11.klaus.repository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest
class EventRepositoryImplTest {
@BeforeEach
void setUp() {
}
@Test
void findEvents() {
}
@AfterEach
void tearDown() {
}
}

View File

@@ -1,25 +0,0 @@
package com.release11.klaus.repository;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class MockedResponseRedisRepositoryTest {
@Autowired
ObjectMapper objectMapper;
@Test
void getMockedResponse() throws JsonProcessingException {
}
@Test
void setMockedResponse() throws JsonProcessingException {
}
}

View File

@@ -0,0 +1,107 @@
package com.release11.klaus.service;
import com.release11.klaus.model.Event;
import com.release11.klaus.model.EventRequestDto;
import com.release11.klaus.repository.EventRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class EtrackServiceImplTest {
@Mock
EventRepository eventRepository;
@InjectMocks
EtrackServiceImpl etrackServiceImpl;
EventRequestDto eventRequestDto;
List<Event> eventList = new ArrayList<>();
@BeforeEach
void setUp() {
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
Event event1 = Event.builder()
.dateTimeStamp(LocalDateTime.of(2018, 9, 9, 0, 0))
.interfaceName("getMockedResponse")
.clientUUID(String.valueOf(uuid1))
.messageId(323)
.thread("superThread")
.level("INFO")
.message("Log message!")
.build();
Event event2 = Event.builder()
.dateTimeStamp(LocalDateTime.of(2020, 5, 2, 13, 22))
.interfaceName("getAllMockedResponse")
.clientUUID(String.valueOf(uuid2))
.thread("superThread")
.level("INFO")
.message("Log message!")
.build();
Event event3 = Event.builder()
.dateTimeStamp(LocalDateTime.of(2020, 3, 2, 16, 12))
.interfaceName("setMockedResponse")
.clientUUID(String.valueOf(uuid1))
.messageId(323)
.thread("superThread")
.level("INFO")
.message("MockedResponse has been setup successfully!")
.build();
Event event4 = Event.builder()
.dateTimeStamp(LocalDateTime.of(2020, 1, 2, 3,4,5))
.interfaceName("deleteMockedResponse")
.clientUUID(String.valueOf(uuid1))
.messageId(22)
.thread("superThread")
.level("INFO")
.message("Message 22 has been removed.")
.build();
eventList.add(event1);
eventList.add(event2);
eventList.add(event3);
eventList.add(event4);
eventRequestDto = EventRequestDto.builder()
.clientUUID(uuid1)
.localDateTimeTo(LocalDateTime.now())
.localDateTimeFrom(LocalDateTime.of(2010, 2, 3, 4, 5,6 ))
.mockedResponseId(323)
.build();
}
@Test
void getEventsByDateTimeAndBusinessKeys() {
when(eventRepository.findEvents(any(), any(), any()))
.thenReturn(eventList);
List<Event> responseList = etrackServiceImpl.getEventsByDateTimeAndBusinessKeys(eventRequestDto);
assertThat(responseList, hasSize(4));
verify(eventRepository).findEvents(any(), any(), any());
}
@AfterEach
void tearDown() { reset(eventRepository); }
}

View File

@@ -1,50 +1,118 @@
package com.release11.klaus.service;
import com.release11.klaus.mappers.MockedMessageMapper;
import com.release11.klaus.mappers.MockedMessageMapperImpl;
import com.release11.klaus.model.MockedMessage;
import com.release11.klaus.model.MockedMessageDto;
import com.release11.klaus.repository.MockedResponseRepository;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.ws.rs.core.MediaType;
import java.util.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@SpringBootTest
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {MockedMessageMapperImpl.class})
class KlausServiceImplTest {
// @Mock
// MockedResponseRedisRepository mockedResponseRedisRepository;
//
// @InjectMocks
// KlausServiceImpl klausServiceImpl;
//
// private final static UUID uuid = UUID.fromString("e4248095-100e-4f1f-8226-e722014ae29f");
// private final static URI uri = URI.create("http//:localhost:8080");
// private static ResponseEntity<String> mockedResponseEntity;
// private static RequestEntity<String> mockedRequestEntity;
// private static mockedMessage mockedMessage = new mockedMessage(uuid, 1, "application/xml", "body",
// new HttpHeaders(), 200);
//
// @BeforeAll
// public static void initializeMockEntities(){
// HttpHeaders httpHeaders = new HttpHeaders();
// mockedResponseEntity = new ResponseEntity<String>("body", httpHeaders, HttpStatus.ACCEPTED);
// mockedRequestEntity = new RequestEntity<String>(HttpMethod.POST, uri);
// }
//
// @Test
// void getMockedResponse() {
//// when(mockedResponseRedisRepository.getMockedResponse(any(), anyInt()))
//// .thenReturn(mockedResponseEntity);
////
//// ResponseEntity<String> responseEntity = klausServiceImpl.getMockedResponse(uuid, 1);
//// assertThat(responseEntity).isNotNull();
//// verify(mockedResponseRedisRepository).getMockedResponse(any(), anyInt());
// }
//
// @Test
// void setMockedResponse() {
// when(mockedResponseRedisRepository.setMockedResponse(any()))
// .thenReturn(mockedResponseEntity);
//
// ResponseEntity<String> responseEntity = klausServiceImpl.setMockedResponse(mockedMessage);
// assertThat(responseEntity).isNotNull();
// verify(mockedResponseRedisRepository).setMockedResponse(any());
// }
@Mock
MockedResponseRepository mockedResponseRepository;
@Mock private MockedMessageMapper mockedMessageMapper;
@InjectMocks
KlausServiceImpl klausService;
UUID uuid;
MockedMessage mockedMessage1;
Map<String, String> httpHeaders;
MockedMessageDto mockedMessageDto1;
MockedMessageDto mockedMessageDto2;
MockedMessageDto mockedMessageDto3;
List<MockedMessage> mockedMessageList = new ArrayList<>();
@BeforeEach
void setUp() {
uuid = UUID.randomUUID();
httpHeaders = new HashMap<>();
mockedMessageDto1 = MockedMessageDto.builder()
.clientUUID(uuid)
.mockedResponseId(323)
.mediaType(MediaType.APPLICATION_JSON)
.messageBody("it's okey to be gey")
.httpHeaders(httpHeaders)
.httpStatus(200)
.build();
mockedMessageDto2 = MockedMessageDto.builder()
.clientUUID(uuid)
.mockedResponseId(3123)
.mediaType(MediaType.APPLICATION_JSON)
.messageBody("some random message")
.httpHeaders(httpHeaders)
.httpStatus(404)
.build();
mockedMessageDto3 = MockedMessageDto.builder()
.clientUUID(uuid)
.mockedResponseId(3233)
.mediaType(MediaType.APPLICATION_XML)
.messageBody("loooking good")
.httpHeaders(httpHeaders)
.httpStatus(205)
.build();
mockedMessage1 = new MockedMessage();
mockedMessageList.add(mockedMessage1);
mockedMessageList.add(mockedMessage1);
mockedMessageList.add(mockedMessage1);
}
@Test
void deleteMockedResponse() {
klausService.deleteMockedResponse(uuid, 323);
verify(mockedResponseRepository).deleteById(any());
}
@Test
void getAllMockedResponses() {
when(mockedResponseRepository.findAllByClientUUID(any()))
.thenReturn(mockedMessageList);
assertThat(klausService.getAllMockedResponses(uuid), hasSize(3));
verify(mockedResponseRepository).findAllByClientUUID(any());
}
@Test
void getMockedResponse() {
when(mockedResponseRepository.getByCompositePrimaryKey(any()))
.thenReturn(mockedMessage1);
assertThat(klausService.getMockedResponse(uuid, 323)).isNotNull();
verify(mockedResponseRepository).findById(any());
}
@Test
void setMockedResponse() {
klausService.setMockedResponse(mockedMessageDto1);
verify(mockedResponseRepository).save(any());
}
@AfterEach
void tearDown() { reset(mockedResponseRepository); }
}