Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.apache.commons.digester3.binder.AbstractRulesModule;
import org.devgateway.ocds.persistence.mongo.Release;
import org.devgateway.ocds.persistence.mongo.repository.ReleaseRepository;
import org.devgateway.toolkit.persistence.mongo.test.AbstractMongoTest;
import org.devgateway.toolkit.persistence.mongo.AbstractMongoTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
Expand All @@ -26,6 +28,18 @@ public class XMLFileImportTest extends AbstractMongoTest {
@Qualifier("XMLFileImportDefault")
private XMLFile xmlFile;

@Before
public final void setUp() throws Exception {
// just be sure that the release collection is empty
releaseRepository.deleteAll();
}

@After
public final void tearDown() {
// be sure to clean up the release collection
releaseRepository.deleteAll();
}

@Test
public void process() throws Exception {
final ClassLoader classLoader = getClass().getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import org.devgateway.ocds.persistence.mongo.Release;
import org.devgateway.ocds.persistence.mongo.repository.ReleaseRepository;
import org.devgateway.toolkit.persistence.mongo.test.AbstractMongoTest;
import org.devgateway.toolkit.persistence.mongo.AbstractMongoTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -15,6 +17,18 @@ public class ReleaseJsonImportTest extends AbstractMongoTest {
@Autowired
private ReleaseRepository releaseRepository;

@Before
public final void setUp() throws Exception {
// just be sure that the release collection is empty
releaseRepository.deleteAll();
}

@After
public final void tearDown() {
// be sure to clean up the release collection
releaseRepository.deleteAll();
}

@Test
public void importObject() throws Exception {
final String jsonRelease = "{\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import org.devgateway.ocds.persistence.mongo.Tender;
import org.devgateway.ocds.persistence.mongo.Transaction;
import org.devgateway.ocds.persistence.mongo.repository.ReleaseRepository;
import org.devgateway.toolkit.persistence.mongo.test.AbstractMongoTest;
import org.devgateway.toolkit.persistence.mongo.AbstractMongoTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

Expand All @@ -24,6 +26,18 @@ public class ReleasePackageJsonImportTest extends AbstractMongoTest {
@Autowired
private ReleaseRepository releaseRepository;

@Before
public final void setUp() throws Exception {
// just be sure that the release collection is empty
releaseRepository.deleteAll();
}

@After
public final void tearDown() {
// be sure to clean up the release collection
releaseRepository.deleteAll();
}

@Test
public void importObjectsPlanning() throws Exception {
final ClassLoader classLoader = getClass().getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.devgateway.ocds.persistence.mongo.Identifier;
import org.devgateway.ocds.persistence.mongo.Organization;
import org.devgateway.ocds.persistence.mongo.repository.OrganizationRepository;
import org.devgateway.toolkit.persistence.mongo.test.AbstractMongoTest;
import org.devgateway.toolkit.persistence.mongo.AbstractMongoTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -18,14 +18,15 @@ public class OrganizationRepositoryTest extends AbstractMongoTest {
@Autowired
private OrganizationRepository organizationRepository;

private String ORG_ID = "1234";
private static final String ORG_ID = "1234";

@Before
public void importTestData() throws IOException, InterruptedException {

if (testDataInitialized) {
return;
}
// be sure that the organization collection is empty
organizationRepository.deleteAll();

final Organization organization = new Organization();
organization.setName("Development Gateway");
Expand Down Expand Up @@ -63,7 +64,6 @@ public void importTestData() throws IOException, InterruptedException {

@Test
public void testOrganizationSaveAndFind() {

final Organization foundOrg = organizationRepository.findOne(ORG_ID);
Assert.assertNotNull(foundOrg);

Expand All @@ -77,7 +77,6 @@ public void testOrganizationSaveAndFind() {

final Organization foundOrg4 = organizationRepository.findByIdOrNameAllIgnoreCase(ORG_ID, ORG_ID);
Assert.assertNotNull(foundOrg4);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.devgateway.ocds.persistence.mongo.repository.RecordRepository;
import org.devgateway.ocds.persistence.mongo.repository.ReleaseRepository;
import org.devgateway.ocds.persistence.mongo.spring.ReleaseCompilerService;
import org.devgateway.toolkit.persistence.mongo.test.AbstractMongoTest;
import org.devgateway.toolkit.persistence.mongo.AbstractMongoTest;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.devgateway.ocds.persistence.mongo.Release;
import org.devgateway.ocds.persistence.mongo.repository.ReleaseRepository;
import org.devgateway.toolkit.persistence.mongo.test.AbstractMongoTest;
import org.devgateway.toolkit.persistence.mongo.AbstractMongoTest;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,15 +16,12 @@ public class ReleaseRepositoryTest extends AbstractMongoTest {

@Test
public void testReleaseSaveAndFind() {

final Release release = new Release();

release.setOcid(ocid);

releaseRepository.insert(release);

final Release byOcid = releaseRepository.findByOcid(ocid);

Assert.assertEquals(ocid, byOcid.getOcid());
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package org.devgateway.toolkit.persistence.mongo.test;
package org.devgateway.toolkit.persistence.mongo;

import org.devgateway.toolkit.persistence.mongo.spring.MongoPersistenceApplication;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

@Configuration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { MongoPersistenceApplication.class })
@ActiveProfiles("integration")
@TestPropertySource("classpath:test.properties")
@WebAppConfiguration
@WebIntegrationTest
/**
* Superclass for all integration tests that use MongoDB.
* Adding this as a superclass will ensure the tests are run with the "integration" spring profile.
Expand All @@ -24,7 +24,5 @@
*
*/
public abstract class AbstractMongoTest {

protected boolean testDataInitialized = false;

protected boolean testDataInitialized;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import org.devgateway.ocds.persistence.mongo.spring.json.JsonImportPackage;
import org.devgateway.ocds.persistence.mongo.spring.json.ReleasePackageJsonImport;
import org.devgateway.toolkit.web.AbstractWebTest;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.util.Collection;
import java.util.List;

/**
Expand All @@ -25,35 +24,39 @@
public abstract class AbstractEndPointControllerTest extends AbstractWebTest {
protected static Logger logger = Logger.getLogger(AbstractEndPointControllerTest.class);

private Collection<Release> releases;

private List<Release> importedRelease;

@Autowired
private ReleaseRepository releaseRepository;

private static ReleaseRepository releaseRepositoryStatic;

@Before
public final void setUp() throws Exception {
// just run the setUp only once and be sure that the release collection is empty
if (testDataInitialized) {
return;
}
releaseRepository.deleteAll();
releaseRepositoryStatic = releaseRepository;

final ClassLoader classLoader = getClass().getClassLoader();

final File file = new File(classLoader.getResource("json/endpoint-data-test.json").getFile());
final JsonImportPackage releasePackageJsonImport = new ReleasePackageJsonImport(releaseRepository, file);
releasePackageJsonImport.importObjects();

this.releases = releasePackageJsonImport.importObjects();
this.importedRelease = releaseRepository.findAll();
testDataInitialized = true;
}

@After
public final void tearDown() {
releaseRepository.deleteAll();
@AfterClass
public static final void tearDown() {
// be sure to clean up the release collection
releaseRepositoryStatic.deleteAll();
}

@Test
public void testImportForEndpoints() {
// just test that the import was done correctly
Assert.assertEquals(3, releases.size());
final List<Release> importedRelease = releaseRepository.findAll();
Assert.assertNotNull(importedRelease);
Assert.assertEquals(3, importedRelease.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
import org.devgateway.ocds.web.rest.controller.selector.OrganizationSearchController;
import org.devgateway.ocds.web.rest.controller.selector.ProcuringEntitySearchController;
import org.devgateway.ocds.web.rest.controller.selector.SupplierSearchController;
import org.devgateway.toolkit.persistence.mongo.spring.MongoTemplateConfiguration;
import org.devgateway.toolkit.persistence.mongo.test.AbstractMongoTest;
import org.devgateway.toolkit.web.AbstractWebTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -20,7 +19,7 @@
import java.io.IOException;
import java.util.List;

public class OrganizationEndpointsTest extends AbstractMongoTest {
public class OrganizationEndpointsTest extends AbstractWebTest {

@Autowired
private OrganizationSearchController organizationSearchController;
Expand All @@ -37,22 +36,18 @@ public class OrganizationEndpointsTest extends AbstractMongoTest {
@Autowired
private OrganizationRepository organizationRepository;

@Autowired
private MongoTemplateConfiguration mongoTemplateConfiguration;


private String orgId = "1234";
private static final String ORG_ID = "1234";

@Before
public void importTestData() throws IOException, InterruptedException {

if (testDataInitialized) {
return;
}
organizationRepository.deleteAll();

final Organization organization = new Organization();
organization.setName("Development Gateway");
organization.setId(orgId);
organization.setId(ORG_ID);

final Address address = new Address();
address.setCountryName("Romania");
Expand All @@ -77,14 +72,14 @@ public void importTestData() throws IOException, InterruptedException {
final Organization savedOrganization = organizationRepository.save(organization);

Assert.assertNotNull(savedOrganization);
Assert.assertEquals(orgId, savedOrganization.getId());
Assert.assertEquals(ORG_ID, savedOrganization.getId());

testDataInitialized = true;
}

@Test
public void testOrganizationIdEndpoint() {
final Organization organizationId = organizationSearchController.byId(orgId);
final Organization organizationId = organizationSearchController.byId(ORG_ID);
Assert.assertNotNull(organizationId);
}

Expand All @@ -98,7 +93,7 @@ public void testOrganizationSearchText() {

@Test
public void testProcuringEntityIdEndpoint() {
final Organization organizationId = procuringEntitySearchController.byId(orgId);
final Organization organizationId = procuringEntitySearchController.byId(ORG_ID);
Assert.assertNotNull(organizationId);
}

Expand All @@ -112,7 +107,7 @@ public void testProcuringEntitySearchText() {

@Test
public void testBuyerIdEndpoint() {
final Organization organizationId = buyerSearchController.byId(orgId);
final Organization organizationId = buyerSearchController.byId(ORG_ID);
Assert.assertNotNull(organizationId);
}

Expand All @@ -126,7 +121,7 @@ public void testBuyerSearchText() {

@Test
public void testSupplierIdEndpoint() {
final Organization organizationId = supplierSearchController.byId(orgId);
final Organization organizationId = supplierSearchController.byId(ORG_ID);
Assert.assertNull(organizationId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.devgateway.ocds.persistence.mongo.spring.json.JsonImport;
import org.devgateway.ocds.persistence.mongo.spring.json.ReleaseJsonImport;
import org.devgateway.toolkit.web.AbstractWebTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -55,6 +56,9 @@ public class ReleaseExportTest extends AbstractWebTest {

@Before
public final void setUp() throws Exception {
// just be sure that the release collection is empty
releaseRepository.deleteAll();

// use a web app context setup because we want to do an integration test that involves loading of
// Controllers, Services and Repositories from the Spring configuration.
// for a more focused unit tests we can use:
Expand All @@ -74,6 +78,12 @@ public final void setUp() throws Exception {
.getJsonSchema(ocdsSchemaNodeAllRequired);
}

@After
public final void tearDown() {
// be sure to clean up the release collection
releaseRepository.deleteAll();
}

@Test
public void testReleaseExportIsValid() throws Exception {
final ClassLoader classLoader = getClass().getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
@TestPropertySource("classpath:test.properties")
@WebIntegrationTest
public abstract class AbstractWebTest {

protected boolean testDataInitialized;
}
Loading