Skip to content

Commit

Permalink
Switching to unit tests (WIP)
Browse files Browse the repository at this point in the history
```
[ERROR] Errors:
[ERROR]   CollectionControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   ConceptControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   DocumentControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   OrganizationControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   PersonControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   ProcessControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   RelationshipControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   CollectionExportControllerTest ┬╗ IllegalState Failed to load ApplicationContex...
[ERROR]   ConceptExportControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   DocumentExportControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   OrganizationExportControllerTest ┬╗ IllegalState Failed to load ApplicationCont...
[ERROR]   PersonExportControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   ProcessExportControllerTest ┬╗ IllegalState Failed to load ApplicationContext
[ERROR]   RelationshipExportControllerTest ┬╗ IllegalState Failed to load ApplicationCont...
[ERROR]   ThemeControllerTest.testChangeActiveTheme ┬╗ IllegalState Failed to load Applic...
[ERROR]   ThemeControllerTest.testCreateActiveTheme ┬╗ IllegalState Failed to load Applic...
[ERROR]   ThemeControllerTest.testCreateTheme ┬╗ IllegalState Failed to load ApplicationC...
[ERROR]   ThemeControllerTest.testDeleteActiveTheme ┬╗ IllegalState Failed to load Applic...
[ERROR]   ThemeControllerTest.testDeleteTheme ┬╗ IllegalState Failed to load ApplicationC...
[ERROR]   ThemeControllerTest.testGetActiveTheme ┬╗ IllegalState Failed to load Applicati...
[ERROR]   ThemeControllerTest.testGetTheme ┬╗ IllegalState Failed to load ApplicationCont...
[ERROR]   ThemeControllerTest.testGetThemes ┬╗ IllegalState Failed to load ApplicationCon...
[ERROR]   ThemeControllerTest.testPatchTheme ┬╗ IllegalState Failed to load ApplicationCo...
[ERROR]   ThemeControllerTest.testPatchThemeColors ┬╗ IllegalState Failed to load Applica...
[ERROR]   ThemeControllerTest.testPatchThemeVariables ┬╗ IllegalState Failed to load Appl...
[ERROR]   ThemeControllerTest.testPatchThemeVariants ┬╗ IllegalState Failed to load Appli...
[ERROR]   ThemeControllerTest.testUpdateTheme ┬╗ IllegalState Failed to load ApplicationC...
[ERROR]   DataAndAnalyticsViewControllerTest.testCreateDataAndAnalyticsView ┬╗ IllegalState
[ERROR]   DataAndAnalyticsViewControllerTest.testDeleteTheme ┬╗ IllegalState Failed to lo...
[ERROR]   DataAndAnalyticsViewControllerTest.testGetDataAndAnalyticsView ┬╗ IllegalState ...
[ERROR]   DataAndAnalyticsViewControllerTest.testGetDataAndAnalyticsViews ┬╗ IllegalState
[ERROR]   DataAndAnalyticsViewControllerTest.testPatchTheme ┬╗ IllegalState Failed to loa...
[ERROR]   DataAndAnalyticsViewControllerTest.testUpdateDataAndAnalyticsView ┬╗ IllegalState
[ERROR]   DirectoryViewControllerTest.testCreateDirectoryView ┬╗ IllegalState Failed to l...
[ERROR]   DirectoryViewControllerTest.testDeleteTheme ┬╗ IllegalState Failed to load Appl...
[ERROR]   DirectoryViewControllerTest.testGetDirectoryView ┬╗ IllegalState Failed to load...
[ERROR]   DirectoryViewControllerTest.testGetDirectoryViews ┬╗ IllegalState Failed to loa...
[ERROR]   DirectoryViewControllerTest.testPatchTheme ┬╗ IllegalState Failed to load Appli...
[ERROR]   DirectoryViewControllerTest.testUpdateDirectoryView ┬╗ IllegalState Failed to l...
[ERROR]   DiscoveryViewControllerTest.testCreateDiscoveryView ┬╗ IllegalState Failed to l...
[ERROR]   DiscoveryViewControllerTest.testDeleteTheme ┬╗ IllegalState Failed to load Appl...
[ERROR]   DiscoveryViewControllerTest.testGetDiscoveryView ┬╗ IllegalState Failed to load...
[ERROR]   DiscoveryViewControllerTest.testGetDiscoveryViews ┬╗ IllegalState Failed to loa...
[ERROR]   DiscoveryViewControllerTest.testPatchTheme ┬╗ IllegalState Failed to load Appli...
[ERROR]   DiscoveryViewControllerTest.testUpdateDiscoveryView ┬╗ IllegalState Failed to l...
[ERROR]   DisplayViewControllerTest.testCreateDisplayView ┬╗ IllegalState Failed to load ...
[ERROR]   DisplayViewControllerTest.testDeleteTheme ┬╗ IllegalState Failed to load Applic...
[ERROR]   DisplayViewControllerTest.testFindDisplayViewByTypesIn ┬╗ IllegalState Failed t...
[ERROR]   DisplayViewControllerTest.testGetDisplayView ┬╗ IllegalState Failed to load App...
[ERROR]   DisplayViewControllerTest.testGetDisplayViews ┬╗ IllegalState Failed to load Ap...
[ERROR]   DisplayViewControllerTest.testPatchTheme ┬╗ IllegalState Failed to load Applica...
[ERROR]   DisplayViewControllerTest.testUpdateDisplayView ┬╗ IllegalState Failed to load ...
[INFO]
[ERROR] Tests run: 297, Failures: 0, Errors: 52, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
```
  • Loading branch information
wwelling committed Feb 26, 2024
1 parent 3273196 commit 0ed2621
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
package edu.tamu.scholars.middleware.discovery;

import static edu.tamu.scholars.middleware.discovery.DiscoveryConstants.DEFAULT_QUERY;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.request.CoreAdminRequest;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.Resource;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import edu.tamu.scholars.middleware.config.SolrTestConfig;
import edu.tamu.scholars.middleware.discovery.component.Indexer;
import edu.tamu.scholars.middleware.discovery.model.AbstractIndexDocument;
import edu.tamu.scholars.middleware.discovery.model.Individual;
import edu.tamu.scholars.middleware.discovery.model.repo.IndividualRepo;

@Import(SolrTestConfig.class)
Expand All @@ -45,13 +28,7 @@ public abstract class AbstractSolrDocumentIntegrationTest<D extends AbstractInde
@Value("${middleware.index.name}")
private String collectionName;

@Autowired
protected SolrClient solrClient;

@Autowired
private List<Indexer> indexers;

@Autowired
@MockBean
protected IndividualRepo repo;

protected List<D> mockDocuments = new ArrayList<D>();
Expand All @@ -60,70 +37,12 @@ public abstract class AbstractSolrDocumentIntegrationTest<D extends AbstractInde

@BeforeAll
public void setup() throws SolrServerException, IOException {
createCore();
createDocuments();

}

@AfterAll
public void cleanup() throws SolrServerException, IOException {
deleteDocuments();
deleteCore();
}

private void createCore() throws SolrServerException, IOException {
CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
createRequest.setCoreName(collectionName);
createRequest.setConfigSet(collectionName);
solrClient.request(createRequest);

indexers.stream()
.filter(i -> i.type().equals(getType()))
.forEach(indexer -> {
indexer.init();
});
}

private void deleteCore() throws SolrServerException, IOException {
CoreAdminRequest.Unload unloadRequest = new CoreAdminRequest.Unload(true);
unloadRequest.setCoreName(collectionName);
solrClient.request(unloadRequest);
}

private void createDocuments() throws SolrServerException, IOException {
assertEquals(0, repo.count(DEFAULT_QUERY, Collections.emptyList()));
ObjectMapper objectMapper = new ObjectMapper();
List<File> mockFiles = getMockFiles();
for (File file : mockFiles) {
Map<String, Object> content = objectMapper.readValue(file, new TypeReference<Map<String, Object>>() {});

solrClient.addBean(collectionName, Individual.from(content));

@SuppressWarnings("unchecked")
D mockDocument = (D) objectMapper.readValue(file, getType());
assertNotNull(mockDocument);
mockDocuments.add(mockDocument);
}
assertTrue(mockDocuments.size() > 0, "No mock documents processed");
solrClient.commit(collectionName);
numberOfDocuments = (int) repo.count(DEFAULT_QUERY, Collections.emptyList());
assertEquals(mockFiles.size(), numberOfDocuments, "Indexed documents count not matching mock documents count");
}

private void deleteDocuments() throws SolrServerException, IOException {
solrClient.deleteByQuery(collectionName, DEFAULT_QUERY);
solrClient.commit(collectionName);
}

private List<File> getMockFiles() throws IOException {
assertTrue(mocksDirectoryResource.exists());
assertTrue(mocksDirectoryResource.isFile());
File mocksDirectory = mocksDirectoryResource.getFile();
assertTrue(mocksDirectory.isDirectory());

return Files.walk(mocksDirectory.toPath().resolve(getDocPath()), 2)
.map(path -> path.toFile())
.filter(file -> file.isFile())
.collect(Collectors.toList());

}

protected String getDocPath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,15 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;

import edu.tamu.scholars.middleware.discovery.AbstractSolrDocumentIntegrationTest;
import edu.tamu.scholars.middleware.discovery.model.AbstractIndexDocument;
import edu.tamu.scholars.middleware.utility.ConstraintDescriptionsHelper;

@SpringBootTest
@AutoConfigureMockMvc
@WebMvcTest
@AutoConfigureRestDocs
public abstract class AbstractSolrDocumentControllerTest<D extends AbstractIndexDocument> extends AbstractSolrDocumentIntegrationTest<D> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
Expand All @@ -37,8 +36,7 @@
import edu.tamu.scholars.middleware.view.model.DisplayView;
import edu.tamu.scholars.middleware.view.model.repo.DisplayViewRepo;

@SpringBootTest
@AutoConfigureMockMvc
@WebMvcTest
@AutoConfigureRestDocs
public abstract class AbstractSolrDocumentExportControllerTest<D extends AbstractIndexDocument> extends AbstractSolrDocumentIntegrationTest<D> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
Expand All @@ -46,8 +45,7 @@
import edu.tamu.scholars.middleware.theme.model.Theme;
import edu.tamu.scholars.middleware.utility.ConstraintDescriptionsHelper;

@SpringBootTest
@AutoConfigureMockMvc
@WebMvcTest
@AutoConfigureRestDocs
public class ThemeControllerTest extends ThemeIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package edu.tamu.scholars.middleware.view;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;

import com.fasterxml.jackson.databind.ObjectMapper;

import edu.tamu.scholars.middleware.view.model.View;
import edu.tamu.scholars.middleware.view.model.repo.ViewRepo;

@SpringBootTest
@AutoConfigureMockMvc
@WebMvcTest
@AutoConfigureRestDocs
public abstract class ResourceViewIntegrationTest<V extends View, R extends ViewRepo<V>> extends ViewIntegrationTest<V, R> {

Expand Down

0 comments on commit 0ed2621

Please sign in to comment.