Author: tpalsulich
Date: Mon Dec 29 20:42:19 2014
New Revision: 1648422
URL: http://svn.apache.org/r1648422
Log:
OODT-762. Migrate protocol/api test resources.
Added:
oodt/trunk/protocol/api/src/test/java/
oodt/trunk/protocol/api/src/test/java/org/
oodt/trunk/protocol/api/src/test/java/org/apache/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocol.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocolFactory.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/TestProtocolFile.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/MockProtocolCliAction.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestBasicVerifyCliAction.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestDownloadCliAction.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestProtocolCliAction.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/config/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/config/MockSpringProtocolConfig.java
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/system/
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/system/TestProtocolManager.java
oodt/trunk/protocol/api/src/test/resources/
oodt/trunk/protocol/api/src/test/resources/test-protocol-config.xml
Removed:
oodt/trunk/protocol/api/src/test/org/
oodt/trunk/protocol/api/src/testdata/
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocol.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocol.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocol.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocol.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol;
+
+//JDK imports
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+//OODT imports
+import org.apache.oodt.cas.protocol.auth.Authentication;
+import org.apache.oodt.cas.protocol.exceptions.ProtocolException;
+import org.apache.oodt.cas.protocol.util.ProtocolFileFilter;
+
+/**
+ * Mock {@link Protocol} for testing
+ *
+ * @author bfoster
+ */
+public class MockProtocol implements Protocol {
+
+ private boolean connected;
+ private ProtocolFile cwd;
+ private String factoryId;
+
+ private List<ProtocolFile> deletedFiles;
+ private List<ProtocolFile> putFiles;
+ private List<ProtocolFile> getFiles;
+ private int timesConnected;
+
+ public MockProtocol(String factoryId) {
+ connected = false;
+ this.factoryId = factoryId;
+ deletedFiles = new ArrayList<ProtocolFile>();
+ putFiles = new ArrayList<ProtocolFile>();
+ getFiles = new ArrayList<ProtocolFile>();
+ timesConnected = 0;
+ }
+
+ public String getFactoryId() {
+ return factoryId;
+ }
+
+ public void connect(String host, Authentication authentication)
+ throws ProtocolException {
+ connected = true;
+ deletedFiles.clear();
+ putFiles.clear();
+ getFiles.clear();
+ timesConnected++;
+ }
+
+ public int getTimesConnected() {
+ return timesConnected;
+ }
+
+ public void close() throws ProtocolException {
+ connected = false;
+ }
+
+ public boolean connected() {
+ return connected;
+ }
+
+ public void cd(ProtocolFile file) throws ProtocolException {
+ cwd = file;
+ }
+
+ public void cdHome() throws ProtocolException {
+ cwd = new ProtocolFile("", true);
+ }
+
+ public void cdRoot() throws ProtocolException {
+ cwd = new ProtocolFile("/", true);
+ }
+
+ public void get(ProtocolFile fromFile, File toFile)
+ throws ProtocolException {
+ getFiles.add(fromFile);
+ }
+
+ public List<ProtocolFile> getGetFiles() {
+ return getFiles;
+ }
+
+ public void put(File fromFile, ProtocolFile toFile)
+ throws ProtocolException {
+ putFiles.add(toFile);
+ }
+
+ public List<ProtocolFile> getPutFiles() {
+ return putFiles;
+ }
+
+ public ProtocolFile pwd() throws ProtocolException {
+ return cwd;
+ }
+
+ public List<ProtocolFile> ls() throws ProtocolException {
+ return Collections.emptyList();
+ }
+
+ public List<ProtocolFile> ls(ProtocolFileFilter filter) throws
ProtocolException {
+ return Collections.emptyList();
+ }
+
+ public void delete(ProtocolFile file) throws ProtocolException {
+ deletedFiles.add(file);
+ }
+
+ public List<ProtocolFile> getDeletedFiles() {
+ return deletedFiles;
+ }
+
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocolFactory.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocolFactory.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocolFactory.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/MockProtocolFactory.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol;
+
+//OODT imports
+import org.apache.oodt.commons.spring.SpringSetIdInjectionType;
+
+/**
+ * Mock {@link ProtocolFactory} for testing
+ *
+ * @author bfoster
+ */
+public class MockProtocolFactory implements ProtocolFactory,
SpringSetIdInjectionType {
+
+ private String schema;
+ private String id;
+
+ public MockProtocol newInstance() {
+ return new MockProtocol(id);
+ }
+
+ public String getSchema() {
+ return schema;
+ }
+
+ public void setSchema(String schema) {
+ this.schema = schema;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/TestProtocolFile.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/TestProtocolFile.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/TestProtocolFile.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/TestProtocolFile.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol;
+
+//JDK imports
+import java.io.File;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link ProtocolFile}
+ *
+ * @author bfoster
+ */
+public class TestProtocolFile extends TestCase {
+
+ public void testInitialState() {
+ String filePath = ProtocolFile.SEPARATOR + "path" +
ProtocolFile.SEPARATOR + "to" + ProtocolFile.SEPARATOR + "file";
+ ProtocolFile pFile = new ProtocolFile(filePath, false);
+ assertEquals(filePath, pFile.getPath());
+ assertEquals("file", pFile.getName());
+ assertFalse(pFile.isDir());
+ assertFalse(pFile.isRelative());
+
+ // Test Parent file
+ String parentPath = ProtocolFile.SEPARATOR + "path" +
ProtocolFile.SEPARATOR + "to";
+ assertEquals(parentPath, pFile.getParent().getPath());
+ assertEquals("to", pFile.getParent().getName());
+ assertTrue(pFile.getParent().isDir());
+ assertFalse(pFile.getParent().isRelative());
+ }
+
+ public void testEquals() {
+ assertEquals(new ProtocolFile("/test/directory", true), new
ProtocolFile(
+ new ProtocolFile("/test", true), "directory",
true));
+ assertEquals(new ProtocolFile(new ProtocolFile("/", true),
"repo", true), new ProtocolFile("/repo", true));
+ assertEquals(new ProtocolFile(new ProtocolFile("/", true), "",
true), new ProtocolFile("/", true));
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestBasicAuthentication.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.auth;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link BasicAuthentication}
+ *
+ * @author bfoster
+ */
+public class TestBasicAuthentication extends TestCase {
+
+ public void testInitialState() {
+ BasicAuthentication auth = new BasicAuthentication("user",
"pass");
+ assertEquals("user", auth.getUser());
+ assertEquals("pass", auth.getPass());
+ }
+
+ public void testNullCase() {
+ try {
+ new BasicAuthentication(null, "pass");
+ fail("Should have thrown IllegalArgumentException");
+ }catch (IllegalArgumentException e) {}
+ try {
+ new BasicAuthentication("user", null);
+ fail("Should have thrown IllegalArgumentException");
+ }catch (IllegalArgumentException e) {}
+ try {
+ new BasicAuthentication(null, null);
+ fail("Should have thrown IllegalArgumentException");
+ }catch (IllegalArgumentException e) {}
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/auth/TestNoAuthentication.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.auth;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link NoAuthentication}.
+ *
+ * @author bfoster
+ */
+public class TestNoAuthentication extends TestCase {
+
+ public void testInitialState() {
+ NoAuthentication auth = new NoAuthentication();
+ assertEquals("", auth.getUser());
+ assertEquals("", auth.getPass());
+ }
+
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/MockProtocolCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/MockProtocolCliAction.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/MockProtocolCliAction.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/MockProtocolCliAction.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.cli.action;
+
+//OODT imports
+import org.apache.oodt.cas.cli.exception.CmdLineActionException;
+
+/**
+ * Mock class for {@ProtocolAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class MockProtocolCliAction extends ProtocolCliAction {
+
+ @Override
+ public void execute(ActionMessagePrinter printer)
+ throws CmdLineActionException {
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestBasicVerifyCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestBasicVerifyCliAction.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestBasicVerifyCliAction.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestBasicVerifyCliAction.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.cli.action;
+
+//JDK imports
+import java.net.URI;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction.ActionMessagePrinter;
+import org.apache.oodt.cas.protocol.Protocol;
+import org.apache.oodt.cas.protocol.auth.Authentication;
+import org.apache.oodt.cas.protocol.config.MockSpringProtocolConfig;
+import org.apache.oodt.cas.protocol.system.ProtocolManager;
+import org.apache.oodt.cas.protocol.verify.ProtocolVerifier;
+
+/**
+ * Test class for {@link BasicVerifyCliAction}
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestBasicVerifyCliAction extends TestCase {
+
+ public void testVerification() throws Exception {
+ BasicVerifyCliAction bva = new BasicVerifyCliAction();
+ bva.setSite("http://localhost");
+ bva.setVerifier(new ProtocolVerifier() {
+ public boolean verify(Protocol protocol, URI site,
+ Authentication auth) {
+ return auth != null && site.toString().equals("http://localhost");
+ }
+ });
+ bva.setProtocolManager(new ProtocolManager(new
MockSpringProtocolConfig()));
+ bva.execute(new ActionMessagePrinter());
+ assertTrue(bva.getLastVerificationResults());
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestDownloadCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestDownloadCliAction.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestDownloadCliAction.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestDownloadCliAction.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.cli.action;
+
+//JDK imports
+import java.net.URISyntaxException;
+
+//OODT imports
+import org.apache.oodt.cas.cli.action.CmdLineAction.ActionMessagePrinter;
+import org.apache.oodt.cas.protocol.MockProtocol;
+import org.apache.oodt.cas.protocol.Protocol;
+import org.apache.oodt.cas.protocol.ProtocolFile;
+import org.apache.oodt.cas.protocol.config.MockSpringProtocolConfig;
+import org.apache.oodt.cas.protocol.system.ProtocolManager;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link DownloadCliAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestDownloadCliAction extends TestCase {
+
+ private ProtocolManager pm;
+
+ @Override
+ public void setUp() {
+ pm = new ProtocolManager(new MockSpringProtocolConfig());
+ }
+
+ public void testCreateProtocol() throws URISyntaxException {
+ DownloadCliAction da = new DownloadCliAction();
+ da.setUrl("http://localhost/some/file");
+ Protocol protocol = da.createProtocol(pm);
+ assertNotNull(protocol);
+ assertTrue(protocol instanceof MockProtocol);
+ assertEquals("http1", ((MockProtocol) protocol).getFactoryId());
+ }
+
+ public void testCreateProtocolFile() throws URISyntaxException {
+ DownloadCliAction da = new DownloadCliAction();
+ da.setUrl("http://localhost/some/file");
+ ProtocolFile file = da.createProtocolFile();
+ assertNotNull(file);
+ assertEquals("/some/file", file.getPath());
+ assertFalse(file.isRelative());
+ assertFalse(file.isDir());
+ }
+
+ public void testFileDownload() throws Exception {
+ DownloadCliAction da = new DownloadCliAction();
+ da.setUrl("http://localhost/some/file");
+ da.setProtocolManager(pm);
+ da.execute(new ActionMessagePrinter());
+ assertNotNull(da.getUsedProtocol());
+ assertTrue(da.getUsedProtocol() instanceof MockProtocol);
+ assertEquals(1, ((MockProtocol)
da.getUsedProtocol()).getGetFiles().size());
+ assertEquals("/some/file", ((MockProtocol)
da.getUsedProtocol()).getGetFiles().get(0).getPath());
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestProtocolCliAction.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestProtocolCliAction.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestProtocolCliAction.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/cli/action/TestProtocolCliAction.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.cli.action;
+
+//JDK imports
+import java.net.URISyntaxException;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link ProtocolCliAction}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestProtocolCliAction extends TestCase {
+
+ public void testInitialState() throws URISyntaxException {
+ MockProtocolCliAction action = new MockProtocolCliAction();
+ action.setUser("user");
+ action.setPass("pass");
+ action.setSite("http://some-site");
+ assertEquals("user", action.getAuthentication().getUser());
+ assertEquals("pass", action.getAuthentication().getPass());
+ assertEquals("http://some-site", action.getSite().toString());
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/config/MockSpringProtocolConfig.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/config/MockSpringProtocolConfig.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/config/MockSpringProtocolConfig.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/config/MockSpringProtocolConfig.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.config;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.oodt.cas.protocol.ProtocolFactory;
+
+/**
+ * Mock {@link SpringProtocolConfig}
+ *
+ * @author bfoster
+ */
+public class MockSpringProtocolConfig extends SpringProtocolConfig {
+
+ private static final String CONFIG_FILE =
"src/test/resources/test-protocol-config.xml";
+
+ public MockSpringProtocolConfig() {
+ super(CONFIG_FILE);
+ }
+
+ public String getConfigFile() {
+ return CONFIG_FILE;
+ }
+
+ public Map<String, List<ProtocolFactory>> getFactoryMap() {
+ return factoryMap;
+ }
+}
Added:
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/system/TestProtocolManager.java
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/system/TestProtocolManager.java?rev=1648422&view=auto
==============================================================================
---
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/system/TestProtocolManager.java
(added)
+++
oodt/trunk/protocol/api/src/test/java/org/apache/oodt/cas/protocol/system/TestProtocolManager.java
Mon Dec 29 20:42:19 2014
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.oodt.cas.protocol.system;
+
+//JDK imports
+import java.net.URI;
+import java.net.URISyntaxException;
+
+//OODT imports
+import org.apache.oodt.cas.protocol.MockProtocol;
+import org.apache.oodt.cas.protocol.Protocol;
+import org.apache.oodt.cas.protocol.auth.Authentication;
+import org.apache.oodt.cas.protocol.auth.NoAuthentication;
+import org.apache.oodt.cas.protocol.config.MockSpringProtocolConfig;
+import org.apache.oodt.cas.protocol.verify.ProtocolVerifier;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link ProtocolManager}.
+ *
+ * @author bfoster
+ */
+public class TestProtocolManager extends TestCase {
+
+ private ProtocolManager protocolManager;
+
+ @Override
+ public void setUp() {
+ protocolManager = new ProtocolManager(new
MockSpringProtocolConfig());
+ }
+
+ public void testInitialState() {
+ assertNotNull(protocolManager.getConfig());
+ }
+
+ public void testProtocolFactoryMapping() throws URISyntaxException {
+ Protocol protocol = protocolManager.getProtocolBySite(new
URI("ftp://localhost"), new NoAuthentication(), null);
+ assertNotNull(protocol);
+ assertTrue(protocol instanceof MockProtocol);
+ MockProtocol mockProtocol = (MockProtocol) protocol;
+ assertEquals("ftp1", mockProtocol.getFactoryId());
+
+ //test that ftp1 was memorized and is returned again even
though a Verifier was supplied this time that would return ftp3
+ protocol = protocolManager.getProtocolBySite(new
URI("ftp://localhost"), new NoAuthentication(), new ProtocolVerifier() {
+ public boolean verify(Protocol protocol, URI site,
+ Authentication auth) {
+ if (protocol instanceof MockProtocol) {
+ MockProtocol mockProtocol =
(MockProtocol) protocol;
+ return
mockProtocol.getFactoryId().equals("ftp3");
+ } else {
+ return false;
+ }
+ }
+ });
+ assertNotNull(protocol);
+ assertTrue(protocol instanceof MockProtocol);
+ mockProtocol = (MockProtocol) protocol;
+ assertEquals("ftp1", mockProtocol.getFactoryId());
+
+ }
+
+ public void testVerifier() throws URISyntaxException {
+ Protocol protocol = protocolManager.getProtocolBySite(new
URI("ftp://localhost"), new NoAuthentication(), new ProtocolVerifier() {
+ public boolean verify(Protocol protocol, URI site,
+ Authentication auth) {
+ if (protocol instanceof MockProtocol) {
+ MockProtocol mockProtocol =
(MockProtocol) protocol;
+ return
mockProtocol.getFactoryId().equals("ftp3");
+ } else {
+ return false;
+ }
+ }
+ });
+ assertTrue(protocol instanceof MockProtocol);
+ MockProtocol mockProtocol = (MockProtocol) protocol;
+ assertEquals("ftp3", mockProtocol.getFactoryId());
+ }
+
+}
Added: oodt/trunk/protocol/api/src/test/resources/test-protocol-config.xml
URL:
http://svn.apache.org/viewvc/oodt/trunk/protocol/api/src/test/resources/test-protocol-config.xml?rev=1648422&view=auto
==============================================================================
--- oodt/trunk/protocol/api/src/test/resources/test-protocol-config.xml (added)
+++ oodt/trunk/protocol/api/src/test/resources/test-protocol-config.xml Mon Dec
29 20:42:19 2014
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!--
+
+ Author: bfoster
+ Description: ProtocolManager Configuration
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:p="http://www.springframework.org/schema/p"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+ <bean
class="org.apache.oodt.commons.spring.postprocessor.SetIdBeanPostProcessor"/>
+
+ <!-- list ProtocolFactories here -->
+ <bean id="ftp1"
class="org.apache.oodt.cas.protocol.MockProtocolFactory">
+ <property name="schema" value="ftp"/>
+ </bean>
+ <bean id="ftp2"
class="org.apache.oodt.cas.protocol.MockProtocolFactory">
+ <property name="schema" value="ftp"/>
+ </bean>
+ <bean id="ftp3"
class="org.apache.oodt.cas.protocol.MockProtocolFactory">
+ <property name="schema" value="ftp"/>
+ </bean>
+
+ <bean id="sftp1"
class="org.apache.oodt.cas.protocol.MockProtocolFactory">
+ <property name="schema" value="sftp"/>
+ </bean>
+ <bean id="sftp2"
class="org.apache.oodt.cas.protocol.MockProtocolFactory">
+ <property name="schema" value="sftp"/>
+ </bean>
+
+ <bean id="http1"
class="org.apache.oodt.cas.protocol.MockProtocolFactory">
+ <property name="schema" value="http"/>
+ </bean>
+
+</beans>