Search in sources :

Example 1 with MockLanguageManager

use of io.wcm.testing.mock.aem.MockLanguageManager in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class NavigationImplTest method internalSetup.

protected void internalSetup() throws WCMException {
    context.load().json(testBase + CoreComponentTestContext.TEST_CONTENT_JSON, "/content");
    context.load().json(testBase + "/test-conf.json", "/conf");
    context.registerService(LanguageManager.class, new MockLanguageManager());
    LiveRelationshipManager relationshipManager = mock(LiveRelationshipManager.class);
    when(relationshipManager.getLiveRelationships(any(Resource.class), isNull(), isNull())).then(invocation -> {
        Object[] arguments = invocation.getArguments();
        Resource resource = (Resource) arguments[0];
        if ("/content/navigation-blueprint".equals(resource.getPath())) {
            LiveRelationship liveRelationship = mock(LiveRelationship.class);
            when(liveRelationship.getTargetPath()).thenReturn("/content/navigation-livecopy");
            final ArrayList<LiveRelationship> relationships = new ArrayList<>();
            relationships.add(liveRelationship);
            final Iterator<LiveRelationship> iterator = relationships.iterator();
            return new RangeIterator() {

                int index = 0;

                @Override
                public void skip(long skipNum) {
                }

                @Override
                public long getSize() {
                    return relationships.size();
                }

                @Override
                public long getPosition() {
                    return index;
                }

                @Override
                public boolean hasNext() {
                    return iterator.hasNext();
                }

                @Override
                public Object next() {
                    index++;
                    return iterator.next();
                }
            };
        }
        return null;
    });
    context.registerService(LiveRelationshipManager.class, relationshipManager);
}
Also used : RangeIterator(javax.jcr.RangeIterator) LiveRelationshipManager(com.day.cq.wcm.msm.api.LiveRelationshipManager) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) LiveRelationship(com.day.cq.wcm.msm.api.LiveRelationship) MockLanguageManager(io.wcm.testing.mock.aem.MockLanguageManager)

Aggregations

LiveRelationship (com.day.cq.wcm.msm.api.LiveRelationship)1 LiveRelationshipManager (com.day.cq.wcm.msm.api.LiveRelationshipManager)1 MockLanguageManager (io.wcm.testing.mock.aem.MockLanguageManager)1 ArrayList (java.util.ArrayList)1 RangeIterator (javax.jcr.RangeIterator)1 Resource (org.apache.sling.api.resource.Resource)1