/** * Tests the S3 access. * * @throws Exception if test fails */ @Test public void s3Test() throws Exception { // Create a real object and mock its initClient method final S3NutDao dao = spy(new S3NutDao("/path", false, null, -1, "wuic", "login", "pwd", false)); // Build client mock final AmazonS3Client client = mock(AmazonS3Client.class); when(dao.initClient()).thenReturn(client); // List returned by client final ObjectListing list = mock(ObjectListing.class); final S3ObjectSummary summary = mock(S3ObjectSummary.class); when(summary.getKey()).thenReturn("[cloud].css"); final S3ObjectSummary summarBis = mock(S3ObjectSummary.class); when(summarBis.getKey()).thenReturn("cloud.css"); when(client.listObjects(any(ListObjectsRequest.class))).thenReturn(list); when(list.getObjectSummaries()).thenReturn(Arrays.asList(summary, summarBis)); // Bytes returned by mocked S3 final byte[] array = ".cloud { text-align : justify;}".getBytes(); final S3Object object = mock(S3Object.class); when(object.getObjectContent()) .thenReturn(new S3ObjectInputStream(new ByteArrayInputStream(array), null)); when(client.getObject(anyString(), anyString())).thenReturn(object); // TODO : problem here : we specify '[cloud.css]' but getNuts() returns 'cloud.css' because // regex are always activated ! final NutsHeap nutsHeap = new NutsHeap(Arrays.asList("[cloud].css"), dao, "heap"); Assert.assertEquals(nutsHeap.getNuts().size(), 1); final Engine compressor = new CssYuiCompressorEngine(true, "UTF-8", -1); final Engine cacheEngine = new EhCacheEngine(false, null); final Engine aggregator = new CGTextAggregatorEngine(true); cacheEngine.setNext(compressor); compressor.setNext(aggregator); final List<Nut> group = cacheEngine.parse(new EngineRequest("", "", nutsHeap, new HashMap<NutType, Engine>())); Assert.assertFalse(group.isEmpty()); InputStream is; for (Nut res : group) { is = res.openStream(); Assert.assertTrue(IOUtils.readString(new InputStreamReader(is)).length() > 0); is.close(); } }