Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add android sdk for Aliyun Message Service #31

Merged
merged 1 commit into from
Aug 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.alibaba.sdk.android.MNSTest;

import android.test.AndroidTestCase;

import com.alibaba.sdk.android.mns.MNS;
import com.alibaba.sdk.android.mns.MNSClient;
import com.alibaba.sdk.android.mns.common.MNSLog;
import com.alibaba.sdk.android.mns.internal.MNSAsyncTask;
import com.alibaba.sdk.android.mns.model.QueueMeta;
import com.alibaba.sdk.android.mns.model.request.CreateQueueRequest;
import com.alibaba.sdk.android.mns.model.request.DeleteQueueRequest;

/**
* Created by pan.zengp on 2016/7/28.
*/
public class CreateQueueTest extends AndroidTestCase {
MNS mns;

@Override
public void setUp() throws Exception{
if (mns == null) {
Thread.sleep(5 * 1000);
MNSLog.enableLog();
mns = new MNSClient(getContext(), MNSTestConfig.ENDPOINT, MNSTestConfig.credentialProvider);
}
}

public void testCreateQueue() throws Exception {
CreateQueueRequest request = new CreateQueueRequest(MNSTestConfig.QUEUE_NAME);
QueueMeta queueMeta = new QueueMeta();
queueMeta.setVisibilityTimeout(60L);
queueMeta.setLoggingEnabled(1);
request.setQueueMeta(queueMeta);
MNSTestConfig.TestCreateQueueCallback callback = new MNSTestConfig.TestCreateQueueCallback();
MNSAsyncTask task = mns.asyncCreateQueue(request, callback);
task.waitUntilFinished();
assertNull(callback.serviceException);
assertNull(callback.clientException);
assertTrue(callback.result.getStatusCode() == 204 || callback.result.getStatusCode() == 201 );

DeleteQueueRequest deleteRequest = new DeleteQueueRequest(MNSTestConfig.QUEUE_NAME);
MNSTestConfig.TestDeleteQueueCallback deleteQueueCallback = new MNSTestConfig.TestDeleteQueueCallback();
MNSAsyncTask deleteTask = mns.asyncDeleteQueue(deleteRequest, deleteQueueCallback);
deleteTask.waitUntilFinished();
assertNull(deleteQueueCallback.serviceException);
assertNull(deleteQueueCallback.clientException);
assertEquals(204, deleteQueueCallback.result.getStatusCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.alibaba.sdk.android.MNSTest;

import android.test.AndroidTestCase;

import com.alibaba.sdk.android.mns.MNS;
import com.alibaba.sdk.android.mns.MNSClient;
import com.alibaba.sdk.android.mns.common.MNSLog;
import com.alibaba.sdk.android.mns.internal.MNSAsyncTask;
import com.alibaba.sdk.android.mns.model.PagingListResult;
import com.alibaba.sdk.android.mns.model.request.ListQueueRequest;

import java.util.List;

/**
* Created by pan.zengp on 2016/7/31.
*/
public class ListQueueTest extends AndroidTestCase {
MNS mns;

@Override
public void setUp() throws Exception {
if (mns == null) {
Thread.sleep(5 * 1000);
MNSLog.enableLog();
mns = new MNSClient(getContext(), MNSTestConfig.ENDPOINT, MNSTestConfig.credentialProvider);
}
}

public void testListQueue() throws Exception {
ListQueueRequest request = new ListQueueRequest("", 100, "");
MNSTestConfig.TestListQueueCallback listQueueCallback = new MNSTestConfig.TestListQueueCallback();
MNSAsyncTask setQueueAttrTask = mns.asyncListQueue(request, listQueueCallback);
setQueueAttrTask.waitUntilFinished();
assertNull(listQueueCallback.clientException);
assertNull(listQueueCallback.serviceException);
assertEquals(200, listQueueCallback.result.getStatusCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
package com.alibaba.sdk.android.MNSTest;

import com.alibaba.sdk.android.common.ClientException;
import com.alibaba.sdk.android.common.ServiceException;
import com.alibaba.sdk.android.common.auth.CredentialProvider;
import com.alibaba.sdk.android.common.auth.PlainTextAKSKCredentialProvider;
import com.alibaba.sdk.android.mns.callback.MNSCompletedCallback;
import com.alibaba.sdk.android.mns.model.request.ChangeMessageVisibilityRequest;
import com.alibaba.sdk.android.mns.model.request.CreateQueueRequest;
import com.alibaba.sdk.android.mns.model.request.DeleteMessageRequest;
import com.alibaba.sdk.android.mns.model.request.DeleteQueueRequest;
import com.alibaba.sdk.android.mns.model.request.GetQueueAttributesRequest;
import com.alibaba.sdk.android.mns.model.request.ListQueueRequest;
import com.alibaba.sdk.android.mns.model.request.PeekMessageRequest;
import com.alibaba.sdk.android.mns.model.request.ReceiveMessageRequest;
import com.alibaba.sdk.android.mns.model.request.SendMessageRequest;
import com.alibaba.sdk.android.mns.model.request.SetQueueAttributesRequest;
import com.alibaba.sdk.android.mns.model.result.ChangeMessageVisibilityResult;
import com.alibaba.sdk.android.mns.model.result.CreateQueueResult;
import com.alibaba.sdk.android.mns.model.result.DeleteMessageResult;
import com.alibaba.sdk.android.mns.model.result.DeleteQueueResult;
import com.alibaba.sdk.android.mns.model.result.GetQueueAttributesResult;
import com.alibaba.sdk.android.mns.model.result.ListQueueResult;
import com.alibaba.sdk.android.mns.model.result.PeekMessageResult;
import com.alibaba.sdk.android.mns.model.result.ReceiveMessageResult;
import com.alibaba.sdk.android.mns.model.result.SendMessageResult;
import com.alibaba.sdk.android.mns.model.result.SetQueueAttributesResult;

/**
* Created by pan.zengp on 2016/7/28.
*/
public class MNSTestConfig {
public static final String ENDPOINT = "http://*************.mns.cn-region.aliyuncs.com";

public static final String AK = "***************";

public static final String SK = "*********************";

public static final CredentialProvider credentialProvider = newAKSKCredentialProvider();

public static final String QUEUE_NAME = "TestAndroidQueue";

public static CredentialProvider newAKSKCredentialProvider() {
return new PlainTextAKSKCredentialProvider(AK, SK);
}

public final static class TestCreateQueueCallback implements MNSCompletedCallback<CreateQueueRequest, CreateQueueResult> {
public CreateQueueRequest request;
public CreateQueueResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(CreateQueueRequest request, CreateQueueResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(CreateQueueRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestDeleteQueueCallback implements MNSCompletedCallback<DeleteQueueRequest, DeleteQueueResult> {
public DeleteQueueRequest request;
public DeleteQueueResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(DeleteQueueRequest request, DeleteQueueResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(DeleteQueueRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestGetQueueAttributesCallback implements MNSCompletedCallback<GetQueueAttributesRequest, GetQueueAttributesResult> {
public GetQueueAttributesRequest request;
public GetQueueAttributesResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(GetQueueAttributesRequest request, GetQueueAttributesResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(GetQueueAttributesRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestSetQueueAttributesCallback implements MNSCompletedCallback<SetQueueAttributesRequest, SetQueueAttributesResult> {
public SetQueueAttributesRequest request;
public SetQueueAttributesResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(SetQueueAttributesRequest request, SetQueueAttributesResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(SetQueueAttributesRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestListQueueCallback implements MNSCompletedCallback<ListQueueRequest, ListQueueResult> {
public ListQueueRequest request;
public ListQueueResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(ListQueueRequest request, ListQueueResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(ListQueueRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestSendMessageCallback implements MNSCompletedCallback<SendMessageRequest, SendMessageResult> {
public SendMessageRequest request;
public SendMessageResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(SendMessageRequest request, SendMessageResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(SendMessageRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestReceiveMessageCallback implements MNSCompletedCallback<ReceiveMessageRequest, ReceiveMessageResult> {
public ReceiveMessageRequest request;
public ReceiveMessageResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(ReceiveMessageRequest request, ReceiveMessageResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(ReceiveMessageRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestDeleteMessageCallback implements MNSCompletedCallback<DeleteMessageRequest, DeleteMessageResult> {
public DeleteMessageRequest request;
public DeleteMessageResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(DeleteMessageRequest request, DeleteMessageResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(DeleteMessageRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestPeekMessageCallback implements MNSCompletedCallback<PeekMessageRequest, PeekMessageResult> {
public PeekMessageRequest request;
public PeekMessageResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(PeekMessageRequest request, PeekMessageResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(PeekMessageRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}

public final static class TestChangeMessageVisibilityCallback implements MNSCompletedCallback<ChangeMessageVisibilityRequest, ChangeMessageVisibilityResult> {
public ChangeMessageVisibilityRequest request;
public ChangeMessageVisibilityResult result;
public ClientException clientException;
public ServiceException serviceException;

@Override
public void onSuccess(ChangeMessageVisibilityRequest request, ChangeMessageVisibilityResult result){
System.out.println("OnSuccess");
this.request = request;
this.result = result;
}

@Override
public void onFailure(ChangeMessageVisibilityRequest request, ClientException clientException, ServiceException serviceException)
{
System.out.println("OnFail");
this.request = request;
this.clientException = clientException;
this.serviceException = serviceException;
}
}
}
Loading