Skip to content

Commit

Permalink
Merge pull request #2919 from SanojPunchihewa/vfs-tests
Browse files Browse the repository at this point in the history
Add tests to validate 'transport.vfs.UpdateLastModified' param when sending local files
  • Loading branch information
SanojPunchihewa authored Jun 20, 2023
2 parents 03b1508 + f9cd3ca commit 53cfeb9
Show file tree
Hide file tree
Showing 2 changed files with 178 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public void init() throws Exception {
addVFSProxy22();
addVFSProxy23();
addVFSProxy24();
addVFSProxy25();
addVFSProxy26();
addVFSProxy27();

CarbonServerExtension.restartServer();
carbonLogReader = new CarbonLogReader();
Expand Down Expand Up @@ -709,6 +712,66 @@ public void testVFSProxyInvalidURI() throws Exception {
carbonLogReader.stop();
}

@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"wso2.esb"}, description = "Test Last Modified timestamp is set to the local file when sending " +
"through VFS Transport Sender")
public void testVFSProxyLocalFileWithLastModified() throws Exception {

String proxyName = "VFSProxy25";

File sourceFile = new File(pathToVfsDir + File.separator + "test.xml");
File targetFile = new File(proxyVFSRoots.get(proxyName) + File.separator + "in" + File.separator + "test.xml");
File outfile = new File(proxyVFSRoots.get(proxyName) + File.separator + "out-test" + File.separator + "test" +
".xml");

FileUtils.copyFile(sourceFile, targetFile);
Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS)
.until(isFileExist(outfile));
Assert.assertTrue(outfile.exists());
Assert.assertEquals(sourceFile.lastModified(), outfile.lastModified(), "The Last Modified timestamp " +
"mismatched");
}

@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"wso2.esb"}, description = "Test Last Modified timestamp not set to the local file when sending " +
"through VFS Transport Sender")
public void testVFSProxyLocalFileWithoutLastModified() throws Exception {

String proxyName = "VFSProxy26";

File sourceFile = new File(pathToVfsDir + File.separator + "test.xml");
File targetFile = new File(proxyVFSRoots.get(proxyName) + File.separator + "in" + File.separator + "test.xml");
File outfile = new File(proxyVFSRoots.get(proxyName) + File.separator + "out" + File.separator + "test.xml");

FileUtils.copyFile(sourceFile, targetFile);
Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS)
.until(isFileExist(outfile));
Assert.assertTrue(outfile.exists());
Assert.assertNotEquals(sourceFile.lastModified(), outfile.lastModified(), "The Last Modified timestamp " +
"matched");
}


@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = {"wso2.esb"}, description = "Test transport.vfs.CreateFolder set to false when sending files" +
"through VFS Transport Sender")
public void testVFSProxyLocalFileWithoutForceCreateFolder() throws Exception {

String proxyName = "VFSProxy27";

File sourceFile = new File(pathToVfsDir + File.separator + "test.xml");
File targetFile = new File(proxyVFSRoots.get(proxyName) + File.separator + "in" + File.separator + "test.xml");
File outfile = new File(proxyVFSRoots.get(proxyName) + File.separator + "out_xml");

FileUtils.copyFile(sourceFile, targetFile);
Awaitility.await().pollInterval(50, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS)
.until(isFileExist(outfile));
Assert.assertTrue(outfile.exists());
Assert.assertEquals(sourceFile.lastModified(), outfile.lastModified(), "The Last Modified timestamp " +
"mismatched");
}


private void addVFSProxy1() throws Exception {

String proxyName = "VFSProxy1";
Expand Down Expand Up @@ -1239,6 +1302,120 @@ private void addVFSProxy24() throws Exception {
addProxy(proxy, proxyName);
}

private void addVFSProxy25() throws Exception {

String proxyName = "VFSProxy25";
OMElement proxy = AXIOMUtil.stringToOM(
"<proxy xmlns=\"http://ws.apache.org/ns/synapse\" name=\"VFSProxy25\" startOnLoad=\"true\" transports=\"vfs jms\">\n"
+ " <target>\n"
+ " <inSequence>\n"
+ " <script language=\"js\">\n"
+ " <![CDATA[ java.lang.Thread.sleep(5000); ]]>\n"
+ " </script>"
+ " <property name=\"OUT_ONLY\" scope=\"default\" type=\"STRING\" value=\"true\"/>\n"
+ " <property expression=\"$trp:FILE_NAME\" name=\"transport.vfs.ReplyFileName\" scope=\"transport\" type=\"STRING\"/>\n"
+ " <call>\n"
+ " <endpoint>\n"
+ " <address uri=\"vfs:file://" + pathToVfsDir + "test" + File.separator +
proxyName + File.separator + "out-test?transport.vfs.CreateFolder=true\">\n"
+ " <suspendOnFailure>\n"
+ " <initialDuration>-1</initialDuration>\n"
+ " <progressionFactor>1</progressionFactor>\n"
+ " </suspendOnFailure>\n"
+ " <markForSuspension>\n"
+ " <retriesBeforeSuspension>0</retriesBeforeSuspension>\n"
+ " </markForSuspension>\n"
+ " </address>\n"
+ " </endpoint>\n"
+ " </call>\n"
+ " </inSequence>\n"
+ " <outSequence/>\n"
+ " <faultSequence/>\n"
+ " </target>\n"
+ " <parameter name=\"transport.PollInterval\">1</parameter>\n"
+ " <parameter name=\"transport.vfs.FileURI\">vfs:file://" + pathToVfsDir + "test" +
File.separator + proxyName + File.separator + "in" + File.separator + "</parameter>\n"
+ " <parameter name=\"transport.vfs.ContentType\">text/xml</parameter>\n"
+ " <parameter name=\"transport.vfs.FileNamePattern\">.*\\.xml</parameter>\n"
+ "</proxy>");
addProxy(proxy, proxyName);
}

private void addVFSProxy26() throws Exception {

String proxyName = "VFSProxy26";
OMElement proxy = AXIOMUtil.stringToOM(
"<proxy xmlns=\"http://ws.apache.org/ns/synapse\" name=\"VFSProxy26\" startOnLoad=\"true\" " +
"transports=\"vfs jms\">\n"
+ " <target>\n"
+ " <inSequence>\n"
+ " <property name=\"OUT_ONLY\" scope=\"default\" type=\"STRING\" value=\"true\"/>\n"
+ " <property expression=\"$trp:FILE_NAME\" name=\"transport.vfs.ReplyFileName\" scope=\"transport\" type=\"STRING\"/>\n"
+ " <call>\n"
+ " <endpoint>\n"
+ " <address uri=\"vfs:file://" + pathToVfsDir + "test" + File.separator +
proxyName + File.separator + "out?transport.vfs.UpdateLastModified=false&amp;transport.vfs" +
".CreateFolder=true\">\n"
+ " <suspendOnFailure>\n"
+ " <initialDuration>-1</initialDuration>\n"
+ " <progressionFactor>1</progressionFactor>\n"
+ " </suspendOnFailure>\n"
+ " <markForSuspension>\n"
+ " <retriesBeforeSuspension>0</retriesBeforeSuspension>\n"
+ " </markForSuspension>\n"
+ " </address>\n"
+ " </endpoint>\n"
+ " </call>\n"
+ " </inSequence>\n"
+ " <outSequence/>\n"
+ " <faultSequence/>\n"
+ " </target>\n"
+ " <parameter name=\"transport.PollInterval\">1</parameter>\n"
+ " <parameter name=\"transport.vfs.FileURI\">vfs:file://" + pathToVfsDir + "test" +
File.separator + proxyName + File.separator + "in" + File.separator + "</parameter>\n"
+ " <parameter name=\"transport.vfs.ContentType\">text/xml</parameter>\n"
+ " <parameter name=\"transport.vfs.FileNamePattern\">.*\\.xml</parameter>\n"
+ "</proxy>");
addProxy(proxy, proxyName);
}

private void addVFSProxy27() throws Exception {

String proxyName = "VFSProxy27";
OMElement proxy = AXIOMUtil.stringToOM(
"<proxy xmlns=\"http://ws.apache.org/ns/synapse\" name=\"VFSProxy27\" startOnLoad=\"true\" " +
"transports=\"vfs jms\">\n"
+ " <target>\n"
+ " <inSequence>\n"
+ " <property name=\"OUT_ONLY\" scope=\"default\" type=\"STRING\" value=\"true\"/>\n"
+ " <property expression=\"$trp:FILE_NAME\" name=\"transport.vfs.ReplyFileName\" scope=\"transport\" type=\"STRING\"/>\n"
+ " <call>\n"
+ " <endpoint>\n"
+ " <address uri=\"vfs:file://" + pathToVfsDir + "test" + File.separator +
proxyName + File.separator + "out_xml\">\n"
+ " <suspendOnFailure>\n"
+ " <initialDuration>-1</initialDuration>\n"
+ " <progressionFactor>1</progressionFactor>\n"
+ " </suspendOnFailure>\n"
+ " <markForSuspension>\n"
+ " <retriesBeforeSuspension>0</retriesBeforeSuspension>\n"
+ " </markForSuspension>\n"
+ " </address>\n"
+ " </endpoint>\n"
+ " </call>\n"
+ " </inSequence>\n"
+ " <outSequence/>\n"
+ " <faultSequence/>\n"
+ " </target>\n"
+ " <parameter name=\"transport.PollInterval\">1</parameter>\n"
+ " <parameter name=\"transport.vfs.FileURI\">vfs:file://" + pathToVfsDir + "test" +
File.separator + proxyName + File.separator + "in" + File.separator + "</parameter>\n"
+ " <parameter name=\"transport.vfs.ContentType\">text/xml</parameter>\n"
+ " <parameter name=\"transport.vfs.FileNamePattern\">.*\\.xml</parameter>\n"
+ "</proxy>");
addProxy(proxy, proxyName);
}

private void addProxy(OMElement proxy, String proxyName) throws IOException {
createProxyVfsRootDir(proxyName);
Utils.deploySynapseConfiguration(proxy, proxyName, Utils.ArtifactType.PROXY, false);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@
<com.sun.jaxb.version>2.3.0</com.sun.jaxb.version>
<com.sun.jaxb.impl.version>2.3.1</com.sun.jaxb.impl.version>

<synapse.version>4.0.0-wso2v38</synapse.version>
<synapse.version>4.0.0-wso2v40</synapse.version>
<imp.pkg.version.synapse>[4.0.0, 4.0.1)</imp.pkg.version.synapse>
<carbon.mediation.version>4.7.175</carbon.mediation.version>
<carbon.crypto.version>1.1.3</carbon.crypto.version>
Expand Down

0 comments on commit 53cfeb9

Please sign in to comment.