Search in sources :

Example 16 with Item

use of org.craftercms.core.service.Item in project engine by craftercms.

the class ContentStoreServiceMockUtils method setUpGetContentFromClassPath.

public static ContentStoreService setUpGetContentFromClassPath(ContentStoreService mock) {
    Answer<Content> getContentAnswer = new Answer<Content>() {

        @Override
        public Content answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            String url;
            if (args.length == 2) {
                url = (String) args[1];
            } else {
                url = (String) args[2];
            }
            Content content = getContentFromClassPath(url);
            if (content == null) {
                throw new PathNotFoundException();
            }
            return content;
        }
    };
    Answer<Boolean> existsAnswer = new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            String url = (String) args[1];
            return new ClassPathResource(url).exists();
        }
    };
    when(mock.getContent(any(Context.class), anyString())).then(getContentAnswer);
    when(mock.getContent(any(Context.class), any(CachingOptions.class), anyString())).then(getContentAnswer);
    when(mock.exists(any(Context.class), anyString())).then(existsAnswer);
    when(mock.findChildren(any(Context.class), anyString())).then(new Answer<List<Item>>() {

        @Override
        public List<Item> answer(InvocationOnMock invocation) throws Throwable {
            String folderUrl = (String) invocation.getArguments()[1];
            Resource folderRes = new ClassPathResource(folderUrl);
            File folder = folderRes.getFile();
            String[] childNames = folder.list();
            List<Item> children = new ArrayList<>(childNames.length);
            for (String childName : childNames) {
                Item child = new Item();
                child.setUrl(folderUrl + "/" + childName);
                children.add(child);
            }
            return children;
        }
    });
    return mock;
}
Also used : Context(org.craftercms.core.service.Context) ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) Mockito.anyString(org.mockito.Mockito.anyString) ClassPathResource(org.springframework.core.io.ClassPathResource) Answer(org.mockito.stubbing.Answer) Item(org.craftercms.core.service.Item) CachingOptions(org.craftercms.core.service.CachingOptions) Content(org.craftercms.core.service.Content) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List) PathNotFoundException(org.craftercms.core.exception.PathNotFoundException) File(java.io.File)

Example 17 with Item

use of org.craftercms.core.service.Item in project engine by craftercms.

the class FolderToIndexItemProcessorTest method createContentStoreService.

private ContentStoreService createContentStoreService() {
    Document dom = mock(Document.class);
    when(dom.asXML()).thenReturn(XML);
    Item item = new Item();
    item.setDescriptorUrl(INDEX_EN_URL);
    item.setDescriptorDom(dom);
    item.setKey(INDEX_EN_URL);
    ContentStoreService storeService = mock(ContentStoreService.class);
    when(storeService.findItem(null, null, INDEX_EN_URL, null)).thenReturn(item);
    return storeService;
}
Also used : Item(org.craftercms.core.service.Item) ContentStoreService(org.craftercms.core.service.ContentStoreService) Document(org.dom4j.Document)

Example 18 with Item

use of org.craftercms.core.service.Item in project engine by craftercms.

the class FolderToIndexItemProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    Item item = new Item();
    item.setFolder(true);
    item.setUrl(WEBSITE_FOLDER_URL);
    Item processedItem = processor.process(null, null, item);
    assertEquals(WEBSITE_FOLDER_URL, processedItem.getUrl());
    assertEquals(INDEX_EN_URL, processedItem.getDescriptorUrl());
    assertEquals(XML, processedItem.getDescriptorDom().asXML());
}
Also used : Item(org.craftercms.core.service.Item) Test(org.junit.Test)

Example 19 with Item

use of org.craftercms.core.service.Item in project engine by craftercms.

the class ToCurrentTargetedVersionItemProcessorTest method testProcess.

@Test
public void testProcess() throws Exception {
    Item item = new Item();
    item.setFolder(false);
    item.setUrl(INDEX_FR_URL);
    Item processedItem = processor.process(null, null, item);
    assertEquals(INDEX_EN_URL, processedItem.getUrl());
}
Also used : Item(org.craftercms.core.service.Item) Test(org.junit.Test)

Example 20 with Item

use of org.craftercms.core.service.Item in project engine by craftercms.

the class ToCurrentTargetedVersionItemProcessorTest method createContentStoreService.

private ContentStoreService createContentStoreService() {
    Item item = new Item();
    item.setUrl(INDEX_EN_URL);
    ContentStoreService storeService = mock(ContentStoreService.class);
    when(storeService.findItem(null, null, INDEX_EN_US_URL, null)).thenReturn(item);
    return storeService;
}
Also used : Item(org.craftercms.core.service.Item) ContentStoreService(org.craftercms.core.service.ContentStoreService)

Aggregations

Item (org.craftercms.core.service.Item)55 Test (org.junit.Test)21 Context (org.craftercms.core.service.Context)19 CachingOptions (org.craftercms.core.service.CachingOptions)8 Document (org.dom4j.Document)8 ArrayList (java.util.ArrayList)7 ContentStoreAdapter (org.craftercms.core.store.ContentStoreAdapter)7 CachingAwareList (org.craftercms.core.util.cache.impl.CachingAwareList)5 InheritLevelsMergeStrategyTest (org.craftercms.core.xml.mergers.impl.strategies.InheritLevelsMergeStrategyTest)4 DecoratedStoreAdapterContext (org.craftercms.engine.util.store.decorators.DecoratedStoreAdapterContext)4 PathNotFoundException (org.craftercms.core.exception.PathNotFoundException)3 TextMetaDataExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataExtractingProcessor)3 Content (org.craftercms.core.service.Content)3 ContentStoreService (org.craftercms.core.service.ContentStoreService)3 Tree (org.craftercms.core.service.Tree)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 StoreException (org.craftercms.core.exception.StoreException)2 ItemProcessor (org.craftercms.core.processors.ItemProcessor)2 ItemProcessorPipeline (org.craftercms.core.processors.impl.ItemProcessorPipeline)2 TextMetaDataCollectionExtractingProcessor (org.craftercms.core.processors.impl.TextMetaDataCollectionExtractingProcessor)2