-
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.
Signed-off-by: Maxwell Brown <[email protected]>
- Loading branch information
1 parent
3c16ef1
commit 387889d
Showing
5 changed files
with
372 additions
and
25 deletions.
There are no files selected for viewing
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
83 changes: 83 additions & 0 deletions
83
...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,83 @@ | ||
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.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); | ||
assert(issueBean.getExpand().equals(expand));; | ||
issueBean.setId(id); | ||
assert(issueBean.getId().equals(id)); | ||
issueBean.setSelf(self); | ||
assert(issueBean.getSelf().equals(self)); | ||
issueBean.setKey(key); | ||
assert(issueBean.getKey().equals(key)); | ||
} | ||
|
||
@Test | ||
public void testMapSettersAndGetters(){ | ||
|
||
issueBean.setRenderedFields(renderedFieldsTestObject); | ||
assert(issueBean.getRenderedFields().equals(renderedFieldsTestObject)); | ||
issueBean.setProperties(propertiesTestObject); | ||
assert(issueBean.getProperties().equals(propertiesTestObject)); | ||
issueBean.setNames(namesTestObject); | ||
assert(issueBean.getNames().equals(namesTestObject)); | ||
issueBean.setFields(fieldsTestObject); | ||
assert(issueBean.getFields().equals(fieldsTestObject)); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...c/test/java/org/opensearch/dataprepper/plugins/source/saas/jira/models/IssueItemTest.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,4 @@ | ||
package org.opensearch.dataprepper.plugins.source.saas.jira.models; | ||
|
||
public class IssueItemTest { | ||
} |
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); | ||
|
||
assert(jsonTypeBean.getType().equals(type)); | ||
assert(jsonTypeBean.getItems().equals(items)); | ||
assert(jsonTypeBean.getSystem().equals(system)); | ||
assert(jsonTypeBean.getCustom().equals(custom)); | ||
assert(jsonTypeBean.getCustomId().equals(customId)); | ||
assert(jsonTypeBean.getConfiguration().equals(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.