Guest User

Untitled

a guest
Jun 2nd, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. @ExtendWith({ AemContextExtension.class, MockitoExtension.class })
  2. class JSONExporterServiceImplTest {
  3.  
  4.     private JSONExporterServiceImpl jsonExporterServiceImpl;
  5.      private final AemContext context = new AemContext(ResourceResolverType.RESOURCERESOLVER_MOCK);
  6.      @Mock
  7.      private ModelFactory modelFactory;
  8.      String json;
  9.      private GamesModel gamesModel;
  10.     @BeforeEach
  11.     void setUp() throws Exception {
  12.        
  13.         context.load().json("/com/warner/media/core/services/sample-content.json","/content");
  14.         context.currentResource("/content");
  15.         json= "{description=games, sling:resourceType=warner/components/games, jcr:primaryType=nt:unstructured, title=gamescomponent}";
  16.             context.registerService(ModelFactory.class, modelFactory, org.osgi.framework.Constants.SERVICE_RANKING,
  17.                     Integer.MAX_VALUE);
  18.         jsonExporterServiceImpl=context.registerInjectActivateService(new JSONExporterServiceImpl());
  19.        
  20.        
  21.     }
  22.  
  23.     @Test
  24.     void testGetContentPageJson() throws PostConstructException, MissingElementsException, InvalidAdaptableException, ModelClassException, ValidationException, InvalidModelException, ExportException, MissingExporterException {
  25.         assertEquals("warner/components/container",context.currentResource().getChild("/content/root/container").getResourceType());
  26.            
  27.         lenient().when(modelFactory.exportModelForResource(context.currentResource().getChild("/content/root/container/cncontainer/games1"), "jackson", String.class, new HashMap<String,String>())).thenReturn(json);
  28.          
  29.         jsonExporterServiceImpl.getContentPageJson(context.request(), context.currentResource(), context.resourceResolver());
  30.     }
Add Comment
Please, Sign In to add comment