diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java index 4ccea548b..973833ec8 100644 --- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java +++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java @@ -1306,10 +1306,9 @@ public abstract class AbstractServices { @PathParam("entityId") String entityId) { try { - final String basePath = - entitySetName + File.separatorChar + Commons.getEntityKey(entityId) + File.separatorChar; + final String basePath = entitySetName + File.separatorChar + Commons.getEntityKey(entityId); - FSManager.instance(version).deleteFile(basePath + Constants.get(version, ConstantKey.ENTITY)); + FSManager.instance(version).deleteEntity(basePath); return xml.createResponse(null, null, null, null, Response.Status.NO_CONTENT); } catch (Exception e) { diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java index 2599b8fe2..4eac3a0e3 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/FSManager.java @@ -35,6 +35,7 @@ import org.apache.commons.vfs2.FileSelectInfo; import org.apache.commons.vfs2.FileSelector; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemManager; +import org.apache.commons.vfs2.FileType; import org.apache.commons.vfs2.VFS; import org.apache.olingo.commons.api.data.ResWrap; import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; @@ -72,6 +73,16 @@ public class FSManager { private FSManager(final ODataServiceVersion version) throws Exception { this.version = version; fsManager = VFS.getManager(); + + final FileObject basePath = fsManager.resolveFile(RES_PREFIX + File.separatorChar + version.name()); + final String absoluteBaseFolder = basePath.getURL().getPath(); + + for (FileObject fo : find(basePath, null)) { + if (fo.getType() == FileType.FILE) { + final String path = fo.getURL().getPath().replace(absoluteBaseFolder, "//" + version.name()); + putInMemory(fo.getContent().getInputStream(), path); + } + } } public String getAbsolutePath(final String relativePath, final Accept accept) { @@ -79,7 +90,7 @@ public class FSManager { + (accept == null ? "" : accept.getExtension()); } - public FileObject putInMemory(final InputStream is, final String path) throws IOException { + public final FileObject putInMemory(final InputStream is, final String path) throws IOException { LOG.info("Write in memory {}", path); final FileObject memObject = fsManager.resolveFile(MEM_PREFIX + path); @@ -116,9 +127,9 @@ public class FSManager { final ObjectMapper mapper = Commons.getJSONMapper(version); mapper.writeValue( writer, new JSONEntryContainer( - container.getContextURL(), - container.getMetadataETag(), - dataBinder.toJSONEntity(container.getPayload()))); + container.getContextURL(), + container.getMetadataETag(), + dataBinder.toJSONEntity(container.getPayload()))); putInMemory(new ByteArrayInputStream(content.toByteArray()), getAbsolutePath(relativePath, Accept.JSON_FULLMETA)); } catch (Exception e) { @@ -135,20 +146,10 @@ public class FSManager { LOG.info("Read {}", path); try { - FileObject fileObject = fsManager.resolveFile(MEM_PREFIX + path); + final FileObject fileObject = fsManager.resolveFile(MEM_PREFIX + path); if (!fileObject.exists()) { LOG.warn("In-memory path '{}' not found", path); - - try { - fileObject = fsManager.resolveFile(RES_PREFIX + path); - fileObject = putInMemory(fileObject.getContent().getInputStream(), path); - } catch (FileSystemException fse) { - LOG.warn("Resource path '{}' not found", path, fse); - } - } - - if (!fileObject.exists()) { throw new NotFoundException(); } @@ -176,12 +177,33 @@ public class FSManager { } } - public FileObject resolve(final String path) throws FileSystemException { - FileObject res = fsManager.resolveFile(MEM_PREFIX + path); + public void deleteEntity(final String relativePath) { + final String path = getAbsolutePath(relativePath, null); + LOG.info("Delete {}", path); - if (!res.exists()) { - res = fsManager.resolveFile(RES_PREFIX + path); + try { + final FileObject fileObject = fsManager.resolveFile(MEM_PREFIX + path); + + if (fileObject.exists()) { + fileObject.delete(new FileSelector() { + @Override + public boolean includeFile(final FileSelectInfo fileInfo) throws Exception { + return true; + } + + @Override + public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception { + return true; + } + }); + } + } catch (IOException ignore) { + // ignore exception } + } + + public FileObject resolve(final String path) throws FileSystemException { + final FileObject res = fsManager.resolveFile(MEM_PREFIX + path); if (!res.exists()) { throw new FileSystemException("Unresolved path " + path); @@ -190,11 +212,11 @@ public class FSManager { return res; } - public FileObject[] findByExtension(final FileObject fo, final String ext) throws FileSystemException { + public final FileObject[] find(final FileObject fo, final String ext) throws FileSystemException { return fo.findFiles(new FileSelector() { @Override public boolean includeFile(final FileSelectInfo fileInfo) throws Exception { - return fileInfo.getFile().getName().getExtension().equals(ext); + return ext == null ? true : fileInfo.getFile().getName().getExtension().equals(ext); } @Override diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java index b4f99693a..84a6cd2e6 100644 --- a/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java +++ b/fit/src/main/java/org/apache/olingo/fit/utils/XMLUtilities.java @@ -598,7 +598,7 @@ public class XMLUtilities extends AbstractUtilities { try { final FileObject skipToken = fsManager.resolve(skipTokenDirPath); - final FileObject[] files = fsManager.findByExtension(skipToken, Accept.XML.getExtension().substring(1)); + final FileObject[] files = fsManager.find(skipToken, Accept.XML.getExtension().substring(1)); for (FileObject file : files) { count += countFeedElements(fsManager.readFile( diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java index de9cdc3b8..0bf0eb58d 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AbstractTestITCase.java @@ -63,8 +63,6 @@ public abstract class AbstractTestITCase { protected static String testLargeModelServiceRootURL; - protected static String testAuthServiceRootURL; - protected final EntityContext entityContext = EntityContainerFactory.getContext().entityContext(); protected static EntityContainerFactory containerFactory; @@ -79,7 +77,6 @@ public abstract class AbstractTestITCase { testActionOverloadingServiceRootURL = "http://localhost:9080/stub/StaticService/V30/ActionOverloading.svc"; testOpenTypeServiceRootURL = "http://localhost:9080/stub/StaticService/V30/OpenType.svc"; testLargeModelServiceRootURL = "http://localhost:9080/stub/StaticService/V30/Static.svc/large"; - testAuthServiceRootURL = "http://localhost:9080/stub/DefaultService.svc"; containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL); containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java similarity index 64% rename from fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java rename to fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java index 7a721a467..d837075be 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AuthEntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityCreateTestITCase.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.olingo.fit.proxy.v3; +package org.apache.olingo.fit.proxy.v4; import static org.junit.Assert.assertNotNull; @@ -24,25 +24,27 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory; +import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.ext.proxy.EntityContainerFactory; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice. - DefaultContainer; +import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.containerFactory; +import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities; -public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase { +public class AuthEntityCreateTestITCase extends EntityCreateTestITCase { @BeforeClass public static void setupContaner() { - containerFactory = EntityContainerFactory.getV3(testAuthServiceRootURL); + containerFactory = EntityContainerFactory.getV4(testAuthServiceRootURL); + containerFactory.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); containerFactory.getClient().getConfiguration(). setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient")); - container = containerFactory.getEntityContainer(DefaultContainer.class); + container = containerFactory.getEntityContainer(InMemoryEntities.class); assertNotNull(container); } @AfterClass public static void disableBasicAuth() { - containerFactory = EntityContainerFactory.getV3(testStaticServiceRootURL); - container = containerFactory.getEntityContainer(DefaultContainer.class); + containerFactory = EntityContainerFactory.getV4(testStaticServiceRootURL); + container = containerFactory.getEntityContainer(InMemoryEntities.class); assertNotNull(container); } } diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java index afe4d006e..c5391d037 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/AuthEntityRetrieveTestITCase.java @@ -18,8 +18,6 @@ */ package org.apache.olingo.fit.proxy.v4; -import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.testKeyAsSegmentServiceRootURL; - import org.apache.olingo.client.api.v4.EdmEnabledODataClient; import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory; @@ -32,7 +30,7 @@ public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase { @Override protected InMemoryEntities getContainer() { final EntityContainerFactory ecf = - EntityContainerFactory.getV4(testKeyAsSegmentServiceRootURL); + EntityContainerFactory.getV4(testAuthServiceRootURL); ecf.getClient().getConfiguration().setKeyAsSegment(true); ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); ecf.getClient().getConfiguration(). diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java index 52cbe51bf..88c4743bf 100644 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityCreateTestITCase.java @@ -29,6 +29,8 @@ import java.util.Calendar; import java.util.Collections; import java.util.TimeZone; import org.apache.commons.lang3.RandomUtils; +import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.container; + import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.AccessLevel; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address; import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Color; @@ -94,7 +96,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase { container.getPeople().delete(actual.getPersonID()); container.flush(); - actual = container.getPeople().get(id, Employee.class);; + actual = container.getPeople().get(id, Employee.class); assertNull(actual); entityContext.detachAll(); @@ -130,7 +132,7 @@ public class EntityCreateTestITCase extends AbstractTestITCase { assertEquals(homeAddress.getCity(), actual.getHomeAddress().getCity()); assertEquals(1, actual.getOrders().size()); assertEquals(8, actual.getOrders().iterator().next().getOrderID(), 0); - + container.getCustomers().delete(actual.getPersonID()); container.flush();