Skip to content

Commit

Permalink
some tests for jira.models
Browse files Browse the repository at this point in the history
Signed-off-by: Maxwell Brown <[email protected]>
  • Loading branch information
Galactus22625 committed Oct 22, 2024
1 parent 3c16ef1 commit 387889d
Show file tree
Hide file tree
Showing 5 changed files with 372 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,31 +127,6 @@ public Map<String, JsonTypeBean> getSchema() {
return schema;
}

@Override
public boolean equals(Object o) {
if (this
== o) {
return true;
}
if (Objects.isNull(o) || getClass() != o.getClass()) {
return false;
}
SearchResults searchResults = (SearchResults) o;
return Objects.equals(this.expand, searchResults.expand)
&& Objects.equals(this.startAt, searchResults.startAt)
&& Objects.equals(this.maxResults, searchResults.maxResults)
&& Objects.equals(this.total, searchResults.total)
&& Objects.equals(this.issues, searchResults.issues)
&& Objects.equals(this.warningMessages, searchResults.warningMessages)
&& Objects.equals(this.names, searchResults.names)
&& Objects.equals(this.schema, searchResults.schema);
}

@Override
public int hashCode() {
return Objects
.hash(expand, startAt, maxResults, total, issues, warningMessages, names, schema);
}

@Override
public String toString() {
Expand Down
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));
}

}
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 {
}
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"));

}
}
Loading

0 comments on commit 387889d

Please sign in to comment.