1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-06 07:32:50 +00:00

Improve documentation and implement a new ServiceID class

This commit is contained in:
2011-11-21 00:57:03 -02:00
parent 1c8db5cf36
commit f210afd16a
23 changed files with 717 additions and 106 deletions

View File

@@ -46,6 +46,7 @@ import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -55,6 +56,7 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
import com.rogiel.httpchannel.service.config.ServiceConfigurationHelper;
import com.rogiel.httpchannel.service.config.ServiceConfigurationProperty;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
@@ -75,6 +77,11 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
public class MegaUploadService extends
AbstractHttpService<MegaUploadServiceConfiguration> implements Service,
UploadService, DownloadService, AuthenticationService {
/**
* This service ID
*/
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
private static final Pattern UPLOAD_URL_PATTERN = Pattern
.compile("http://www([0-9]*)\\.megaupload\\.com/upload_done\\.php\\?UPLOAD_IDENTIFIER=[0-9]*");
@@ -91,13 +98,14 @@ public class MegaUploadService extends
private static final Pattern LOGIN_USERNAME_PATTERN = Pattern
.compile("flashvars\\.username = \"(.*)\";");
public MegaUploadService(final MegaUploadServiceConfiguration configuration) {
super(configuration);
public MegaUploadService() {
super(ServiceConfigurationHelper
.defaultConfiguration(MegaUploadServiceConfiguration.class));
}
@Override
public String getID() {
return "megaupload";
public ServiceID getID() {
return SERVICE_ID;
}
@Override

View File

@@ -0,0 +1 @@
com.rogiel.httpchannel.service.impl.MegaUploadService

View File

@@ -0,0 +1,34 @@
/*
* This file is part of seedbox <github.com/seedbox>.
*
* seedbox is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* seedbox is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with seedbox. If not, see <http://www.gnu.org/licenses/>.
*/
package com.rogiel.httpchannel.service.impl;
import junit.framework.Assert;
import org.junit.Test;
import com.rogiel.httpchannel.service.Services;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class DiscoveryTest {
@Test
public void testDiscovery() {
Assert.assertNotNull(Services.getService(MegaUploadService.SERVICE_ID));
}
}

View File

@@ -45,6 +45,7 @@ import com.rogiel.httpchannel.service.DownloadListener;
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceHelper;
import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.UploaderCapability;
@@ -76,9 +77,7 @@ public class MegaUploadServiceTest {
@Before
public void setUp() throws Exception {
// MegaUploadServiceConfiguration.class;
service = new MegaUploadService(
ServiceConfigurationHelper
.defaultConfiguration(MegaUploadServiceConfiguration.class));
service = new MegaUploadService();
helper = new ServiceHelper(service);
final Properties properties = new Properties();
@@ -91,7 +90,7 @@ public class MegaUploadServiceTest {
@Test
public void testServiceId() {
System.out.println("Service: " + service.toString());
assertEquals("megaupload", service.getID());
assertEquals(ServiceID.create("megaupload"), service.getID());
}
@Test
@@ -116,14 +115,14 @@ public class MegaUploadServiceTest {
final UploadChannel channel = helper.upload(path,
"httpchannel test upload");
final SeekableByteChannel inChannel = Files.newByteChannel(path);
try {
ChannelUtils.copy(inChannel, channel);
} finally {
inChannel.close();
channel.close();
}
System.out.println(channel.getDownloadLink());
Assert.assertNotNull(channel.getDownloadLink());
}
@@ -142,14 +141,14 @@ public class MegaUploadServiceTest {
final UploadChannel channel = helper.upload(path,
"httpchannel test upload");
final SeekableByteChannel inChannel = Files.newByteChannel(path);
try {
ChannelUtils.copy(inChannel, channel);
} finally {
inChannel.close();
channel.close();
}
System.out.println(channel.getDownloadLink());
Assert.assertNotNull(channel.getDownloadLink());
}
@@ -195,7 +194,8 @@ public class MegaUploadServiceTest {
@Test
public void testNoWaitDownloader() throws IOException,
MalformedURLException {
service = new MegaUploadService(ServiceConfigurationHelper.file(
service = new MegaUploadService();
service.setServiceConfiguration(ServiceConfigurationHelper.file(
MegaUploadServiceConfiguration.class, new File(
"src/test/resources/megaupload-nowait.properties")));