Skip to content

Commit

Permalink
added unit and e2e tests for the changes on search operators
Browse files Browse the repository at this point in the history
  • Loading branch information
holashchand committed Jan 19, 2024
1 parent bac3b8e commit d5929b1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ test: build
@docker-compose down
@rm -rf db-data-1 || echo "no permission to delete"
# test with kafka(async), events, notifications,
@docker-compose --env-file test_environments/test_with_asyncCreate_events_notifications.env up -d db clickhouse redis keycloak registry certificate-signer certificate-api kafka zookeeper notification-ms metrics
@docker-compose --env-file test_environments/test_with_asyncCreate_events_notifications.env up -d db es clickhouse redis keycloak registry certificate-signer certificate-api kafka zookeeper notification-ms metrics
@echo "Starting the test" && sh build/wait_for_port.sh 8080
@echo "Starting the test" && sh build/wait_for_port.sh 8081
@docker-compose ps
Expand Down
6 changes: 6 additions & 0 deletions java/apitest/src/test/java/e2e/registry/TeacherRequest2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "abc def",
"gender": "male",
"contact": "1238",
"email": "[email protected]"
}
20 changes: 19 additions & 1 deletion java/apitest/src/test/java/e2e/registry/registry.feature
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,28 @@ Feature: Registry api tests
Then status 200
And response.result.Teacher.transactionId.length > 0
* sleep(7000)
# create entity for teacher
Given url registryUrl
And path 'api/v1/Teacher?mode=async'
* def teacherRequest = read('TeacherRequest2.json')
And request teacherRequest
When method post
Then status 200
And response.result.Teacher.transactionId.length > 0
* sleep(7000)
# get teacher info
Given url registryUrl
And path 'api/v1/Teacher/search'
And request {"filters":{}}
And request {"filters":{ "name": { "eq": "abc" }}}
When method post
Then status 200
* print response
And response.length == 1
And response[0].contact == '#notpresent'
# get teacher info
Given url registryUrl
And path 'api/v1/Teacher/search'
And request {"filters":{ "name": { "endsWith": "abc" }}}
When method post
Then status 200
* print response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package dev.sunbirdrc.registry.dao.impl;

import static org.junit.Assert.assertTrue;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.sunbirdrc.pojos.Filter;
Expand All @@ -27,6 +25,7 @@
import javax.annotation.PreDestroy;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.hamcrest.core.Every;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
Expand All @@ -37,6 +36,8 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import static org.junit.Assert.*;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = { DefinitionsManager.class, ObjectMapper.class, DBProviderFactory.class, DBConnectionInfoMgr.class, OSResourceLoader.class })
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
Expand Down Expand Up @@ -79,21 +80,25 @@ public void initializeGraph() throws IOException {
public void test_search_no_response() throws AuditFailedException, EncryptionException, RecordNotFoundException {
SearchQuery searchQuery = getSearchQuery(entities, "", "", FilterOperators.eq);//new SearchQuery("", 0, 0);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 0);
assertTrue(result.get("Teacher").isEmpty());
}

@Test
public void testEqOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "marko", FilterOperators.eq);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 1);
result.get("Teacher").forEach(d -> {
assertEquals("marko", d.get("teacherName").asText());
});
}

@Test
public void testNeqOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "marko", FilterOperators.neq);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 2);
result.get("Teacher").forEach(d -> {
assertNotEquals("marko", d.get("teacherName").asText());
});
}

@Test
Expand All @@ -103,7 +108,10 @@ public void testRangeOperator() {
range.add(3);
SearchQuery searchQuery = getSearchQuery(entities, "serialNum", range, FilterOperators.between);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 2);
result.get("Teacher").forEach(d -> {
assertTrue(d.get("serialNum").asLong() >= 1);
assertTrue(d.get("serialNum").asLong() <= 3);
});
}

@Test
Expand All @@ -114,33 +122,60 @@ public void testOrOperator() {
values.add(VALUE_NOT_PRESENT);
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", values, FilterOperators.or);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 2);
result.get("Teacher").forEach(d -> {
assertTrue(values.contains(d.get("teacherName").asText()));
});
}

@Test
public void testStartsWithOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "ma", FilterOperators.startsWith);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 1);
result.get("Teacher").forEach(d -> {
assertTrue(d.get("teacherName").asText().startsWith("ma"));
});
}
@Test
public void testNotStartsWithOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "ma", FilterOperators.notStartsWith);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 2);
result.get("Teacher").forEach(d -> {
assertFalse(d.get("teacherName").asText().startsWith("ma"));
});
}

@Test
public void testEndsWithOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "as", FilterOperators.endsWith);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 2);
result.get("Teacher").forEach(d -> {
assertTrue(d.get("teacherName").asText().endsWith("as"));
});
}
@Test
public void testNotEndsWithOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "as", FilterOperators.notEndsWith);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 1);
result.get("Teacher").forEach(d -> {
assertFalse(d.get("teacherName").asText().endsWith("as"));
});
}

@Test
public void testContainsOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "as", FilterOperators.contains);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
result.get("Teacher").forEach(d -> {
assertTrue(d.get("teacherName").asText().contains("as"));
});
}
@Test
public void testNotContainsOperator() {
SearchQuery searchQuery = getSearchQuery(entities, "teacherName", "as", FilterOperators.notContains);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
result.get("Teacher").forEach(d -> {
assertFalse(d.get("teacherName").asText().contains("as"));
});
}
@Test
public void testMultiOperators() {
Expand All @@ -152,14 +187,14 @@ public void testMultiOperators() {
searchQuery.getFilters().add(new Filter("serialNum", FilterOperators.gt, 1));

JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 0);
assertTrue(result.get("Teacher").isEmpty());
}

@Test
public void testResponseLimit() {
SearchQuery searchQuery = new SearchQuery(entities, offset, limit);
JsonNode result = searchDao.search(graph, searchQuery, expandInternal);
assertTrue(result.get("Teacher").size() == 1);
assertEquals(1, result.get("Teacher").size());
}

@PreDestroy
Expand Down Expand Up @@ -187,6 +222,12 @@ private void populateGraph() {
Vertex v3 = vertexWriter.createVertex("Teacher");
v3.property("serialNum", 3);
v3.property("teacherName", "jas");
Vertex v4 = vertexWriter.createVertex("Teacher");
v4.property("serialNum", 4);
v4.property("teacherName", "markus marko");
Vertex v5 = vertexWriter.createVertex("Teacher");
v5.property("serialNum", 5);
v5.property("teacherName", "sodi jas jakob");
}

private SearchQuery getSearchQuery(SearchQuery searchQuery, Filter filter, String type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TRACK_NOTIFICATIONS=true
EVENT_ENABLED=true
ASYNC_ENABLED=true
RELEASE_VERSION=latest
SEARCH_PROVIDER_NAME=dev.sunbirdrc.registry.service.ElasticSearchService
NOTIFICATION_URL=http://notification-ms:8765/notification-service/v1/notification
KEYCLOAK_IMPORT_DIR=java/apitest/src/test/resources
KEYCLOAK_SECRET=a52c5f4a-89fd-40b9-aea2-3f711f14c889
Expand Down

0 comments on commit d5929b1

Please sign in to comment.