-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Galactus22625/Jira-Models-Unit-Tests
Jira models unit tests
- Loading branch information
Showing
5 changed files
with
369 additions
and
84 deletions.
There are no files selected for viewing
59 changes: 0 additions & 59 deletions
59
...e/src/main/java/org/opensearch/dataprepper/plugins/source/saas/jira/models/IssueItem.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...c/test/java/org/opensearch/dataprepper/plugins/source/saas/jira/models/IssueBeanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.models; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class IssueBeanTest { | ||
|
||
@Mock | ||
private Map<String, Object> renderedFieldsTestObject; | ||
|
||
@Mock | ||
private Map<String, Object> propertiesTestObject; | ||
|
||
@Mock | ||
private Map<String, String> namesTestObject; | ||
|
||
@Mock | ||
private Map<String, Object> fieldsTestObject; | ||
|
||
private IssueBean issueBean; | ||
|
||
@BeforeEach | ||
void setup(){ | ||
issueBean = new IssueBean(); | ||
} | ||
|
||
@Test | ||
public void testInitialization(){ | ||
assertNotNull(issueBean); | ||
} | ||
|
||
@Test | ||
public void testNull(){ | ||
assertNull(issueBean.getExpand()); | ||
assertNull(issueBean.getId()); | ||
assertNull(issueBean.getSelf()); | ||
assertNull(issueBean.getKey()); | ||
assertNull(issueBean.getRenderedFields()); | ||
assertNull(issueBean.getProperties()); | ||
assertNull(issueBean.getNames()); | ||
assertNull(issueBean.getFields()); | ||
} | ||
|
||
@Test | ||
public void testStringSettersAndGetters(){ | ||
String self = "selfTest"; | ||
String key = "keyTest"; | ||
String id = "idTest"; | ||
String expand = "expandTest"; | ||
|
||
issueBean.setExpand(expand); | ||
assertEquals(issueBean.getExpand(), expand);; | ||
issueBean.setId(id); | ||
assertEquals(issueBean.getId(), id); | ||
issueBean.setSelf(self); | ||
assertEquals(issueBean.getSelf(), self); | ||
issueBean.setKey(key); | ||
assertEquals(issueBean.getKey(), key); | ||
} | ||
|
||
@Test | ||
public void testMapSettersAndGetters(){ | ||
|
||
issueBean.setRenderedFields(renderedFieldsTestObject); | ||
assertEquals(issueBean.getRenderedFields(), renderedFieldsTestObject); | ||
issueBean.setProperties(propertiesTestObject); | ||
assertEquals(issueBean.getProperties(), propertiesTestObject); | ||
issueBean.setNames(namesTestObject); | ||
assertEquals(issueBean.getNames(), namesTestObject); | ||
issueBean.setFields(fieldsTestObject); | ||
assertEquals(issueBean.getFields(), fieldsTestObject); | ||
} | ||
|
||
} |
163 changes: 163 additions & 0 deletions
163
...est/java/org/opensearch/dataprepper/plugins/source/saas/jira/models/JsonTypeBeanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.models; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class JsonTypeBeanTest { | ||
|
||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
@Mock | ||
private Map<String, Object> testConfiguration; | ||
|
||
private JsonTypeBean jsonTypeBean; | ||
|
||
@BeforeEach | ||
public void setup() throws JsonProcessingException { | ||
String state = "{}"; | ||
jsonTypeBean = objectMapper.readValue(state, JsonTypeBean.class); | ||
} | ||
|
||
@Test | ||
public void testConstructor() { | ||
assertNotNull(jsonTypeBean); | ||
|
||
assertNull(jsonTypeBean.getType()); | ||
assertNull(jsonTypeBean.getItems()); | ||
assertNull(jsonTypeBean.getSystem()); | ||
assertNull(jsonTypeBean.getCustom()); | ||
assertNull(jsonTypeBean.getCustomId()); | ||
assertNull(jsonTypeBean.getConfiguration()); | ||
} | ||
|
||
@Test | ||
public void testGetters() throws JsonProcessingException { | ||
String type = "typeTest"; | ||
String items = "itemsTest"; | ||
String system = "systemTest"; | ||
String custom = "customTest"; | ||
Long customId = 123L; | ||
Map<String, Object> map = new HashMap<>(); | ||
map.put("type", type); | ||
map.put("items", items); | ||
map.put("system", system); | ||
map.put("custom", custom); | ||
map.put("customId", customId); | ||
map.put("configuration", testConfiguration); | ||
|
||
String jsonString = objectMapper.writeValueAsString(map); | ||
|
||
jsonTypeBean = objectMapper.readValue(jsonString, JsonTypeBean.class); | ||
|
||
assertEquals(jsonTypeBean.getType(), type); | ||
assertEquals(jsonTypeBean.getItems(), items); | ||
assertEquals(jsonTypeBean.getSystem(), system); | ||
assertEquals(jsonTypeBean.getCustom(), custom); | ||
assertEquals(jsonTypeBean.getCustomId(), customId); | ||
assertEquals(jsonTypeBean.getConfiguration(), testConfiguration); | ||
} | ||
|
||
@Test | ||
public void testEquals() throws JsonProcessingException { | ||
assertTrue(jsonTypeBean.equals(jsonTypeBean)); | ||
|
||
assertFalse(jsonTypeBean.equals(null)); | ||
assertFalse(jsonTypeBean.equals(new Object())); | ||
|
||
JsonTypeBean sameEntryBean; | ||
JsonTypeBean differentEntryBean; | ||
|
||
String type = "typeTest"; | ||
String items = "itemsTest"; | ||
String system = "systemTest"; | ||
String custom = "customTest"; | ||
Long customId = 123L; | ||
|
||
Map<String, Object> map = new HashMap<>(); | ||
map.put("type", type); | ||
map.put("items", items); | ||
map.put("system", system); | ||
map.put("custom", custom); | ||
map.put("customId", customId); | ||
map.put("configuration", testConfiguration); | ||
|
||
String jsonString = objectMapper.writeValueAsString(map); | ||
|
||
jsonTypeBean = objectMapper.readValue(jsonString, JsonTypeBean.class); | ||
sameEntryBean = objectMapper.readValue(jsonString, JsonTypeBean.class); | ||
|
||
for (String key : map.keySet()) { | ||
String oldString = ""; | ||
if (key.equals("customId")){ | ||
map.put(key, 456L); | ||
} | ||
else if(key.equals("configuration")){ | ||
Map<String, Object> differentTestConfiguration = new HashMap<>(); | ||
differentTestConfiguration.put("differentKey", new JsonTypeBean()); | ||
map.put("configuration", differentTestConfiguration); | ||
} | ||
else { | ||
oldString = map.get(key).toString(); | ||
map.put(key, "different"); | ||
} | ||
differentEntryBean = objectMapper.readValue(objectMapper.writeValueAsString(map), JsonTypeBean.class); | ||
assertTrue(jsonTypeBean.equals(sameEntryBean)); | ||
assertFalse(jsonTypeBean.equals(differentEntryBean)); | ||
if (key.equals("customId")){ | ||
map.put(key, 123); | ||
} | ||
else if(key.equals("configuration")){ | ||
map.put("configuration", testConfiguration); | ||
} | ||
else { | ||
map.put(key, oldString); | ||
} | ||
} | ||
} | ||
@Test | ||
public void testHashCode() throws JsonProcessingException { | ||
assertTrue(jsonTypeBean.hashCode() > 0); | ||
String state = "{\"type\": \"same\"}"; | ||
String state2 = "{\"type\": \"different\"}"; | ||
|
||
JsonTypeBean sameEntryBean; | ||
JsonTypeBean differentEntryBean; | ||
|
||
jsonTypeBean = objectMapper.readValue(state, JsonTypeBean.class); | ||
sameEntryBean = objectMapper.readValue(state, JsonTypeBean.class); | ||
differentEntryBean = objectMapper.readValue(state2, JsonTypeBean.class); | ||
|
||
assertEquals(jsonTypeBean.hashCode(), sameEntryBean.hashCode()); | ||
assertNotEquals(jsonTypeBean.hashCode(), differentEntryBean.hashCode()); | ||
} | ||
@Test | ||
public void testToString() throws JsonProcessingException { | ||
String state = "{\"type\": \"same\"}"; | ||
jsonTypeBean = objectMapper.readValue(state, JsonTypeBean.class); | ||
String jsonString = jsonTypeBean.toString(); | ||
assertTrue(jsonString.contains(JsonTypeBean.class.getSimpleName())); | ||
assertTrue(jsonString.contains("type: same")); | ||
assertTrue(jsonString.contains("items: null")); | ||
assertTrue(jsonString.contains("system")); | ||
assertTrue(jsonString.contains("custom")); | ||
assertTrue(jsonString.contains("customId")); | ||
assertTrue(jsonString.contains("configuration")); | ||
|
||
} | ||
} |
Oops, something went wrong.