Skip to content
Open
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
68 changes: 68 additions & 0 deletions src/test/java/ru/odnoklassniki/homeworkDemoTests/TestGetInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package ru.odnoklassniki.homeworkDemoTests;

import org.junit.Assert;
import org.junit.Test;
import ru.odnoklassniki.base.ApiTestBase;
import ru.odnoklassniki.common.ApiException;
import ru.odnoklassniki.common.group.GroupBean;
import ru.odnoklassniki.common.group.GroupBeanField;

/**
* Created by Soldatov Artem as demotests
*/

public class TestGetInfo extends ApiTestBase {
private static final Logger LOGGER = Logger.getLogger(TestGroupGetInfo.class.getSimpleName());
private static final String GROUP_ID = "58456218710542";
private static final String GROUP_NAME = "Test Group Name 1";
private static final GroupBeanField[] FIELDS = new GroupBeanField[]{GroupBeanField.UID, GroupBeanField.NAME};


@Test
public void testMethodWithValidData() {
LOGGER.info("check metod returns a collection of the correct length");

bindDefaultUserSession();

GroupBean[] groupBeans = okApi.getGroupService().getGroupInfo(new String[]{GROUP_ID}, FIELDS);

Assert.assertThat(
"Incorrect size of the collection",
groupBeans,
allOf(
notNullValue(),
arrayWithSize(equalTo(1))
)
);

LOGGER.info("collection has correct length");
}

@Test
public void testParamUidsIsRequired() {
LOGGER.info("check exception in the absence of uids");
bindDefaultUserSession();
try {
GroupBean[] groupBeans = okApi.getGroupService().getGroupInfo(new String[]{}, FIELDS);
Assert.fail("Method did not throw exception in the absence of uids");
} catch (IllegalArgumentException e) {
Assert.assertEquals("PARAM : Missing required parameter uids", e.getApiErrorInfo().getErrorMessage());
}
LOGGER.info("exception in the absence of uids correct");
}

@Test
public void testParamUidsIsRequired() {
LOGGER.info("check empty fields working");
bindDefaultUserSession();
try {
okApi.getGroupService().getGroupInfo(new String[]{GROUP_ID}, new GroupBeanField[]{});
Assert.fail("Method did not throw exception in the absence of fields");
} catch (IllegalArgumentException e) {
Assert.assertEquals("PARAM : Missing required parameter fields", e.getApiErrorInfo().getErrorMessage());
}
LOGGER.info("exception in the absence of fields correct");
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package ru.odnoklassniki.tests.examples;

import org.junit.Assert;
import org.junit.Test;
import ru.odnoklassniki.base.ApiTestBase;
import ru.odnoklassniki.common.ApiException;
import ru.odnoklassniki.common.group.UserBean;
import ru.odnoklassniki.common.users.UserInfoField;
import ru.odnoklassniki.responses.users.UsersGetInfoByResponse;

import java.util.logging.Logger;

/**
* Created by Soldatov Artem as demotests
*/
public class TestUsersGetInfoBy extends ApiTestBase {
private static final Logger LOGGER = Logger.getLogger(TestUsersGetInfoBy.class.getSimpleName());
private static final String USER_ID = "58456218710542";
private static final String USER_NAME = "Donald Trump";
private static final UserInfoField[] FIELDS = UserInfoField.values();

@Test
public void testUsersGetInfoWithValidData() throws ApiException {
LOGGER.info("try to get data with correct uid and field");
bindDefaultUserSession();

UsersGetInfoByResponse getInfoByResponse = okApi.getUserService().getInfoBy(USER_ID, FIELDS);

UserBean userBean = getInfoByResponse.getUser();
Assert.assertNotNull("no user data", userBean);
Assert.assertEquals("invalid user id", USER_ID, userBean.getUid());
Assert.assertEquals("invalid user name", USER_NAME, userBean.getName());
}

@Test
public void testUserSessionIsRequired() throws ApiException {
LOGGER.info("try to get info without session");
try {
GroupBean[] groupBeans = okApi.getUserService().getInfoBy(USER_ID, FIELDS);
Assert.fail("Method did not throw exception without session");
} catch (IllegalArgumentException e) {
Assert.assertEquals("Session Is Required", e.getApiErrorInfo().getErrorMessage());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ru.odnoklassniki.tests.examples;

import org.junit.Assert;
import org.junit.Test;
import org.springframework.util.CollectionUtils;
import ru.odnoklassniki.base.ApiTestBase;
import ru.odnoklassniki.common.ApiException;
import ru.odnoklassniki.responses.group.GroupGetUserGroupsV2Response;

import java.util.logging.Logger;

/**
* Created by Soldatov Artem as demotests
*/
public class TestGroupGetUserGroupsV2 extends ApiTestBase {
private static final Logger LOGGER = Logger.getLogger(TestGroupGetUserGroupsV2.class.getSimpleName());

@Test
public void testGroupGetUserGroupsV2Example() throws ApiException {
LOGGER.info("Get user groups info");
bindDefaultUserSession();

GroupGetUserGroupsV2Response groupGetUserGroupsV2Response = okApi.getGroupService().getUserGroupsV2();
Assert.assertFalse("Empty group list", CollectionUtils.isEmpty(groupGetUserGroupsV2Response.getGroups()));
LOGGER.info("group data obtained");
}

@Test
public void testUserSessionIsRequired() {
LOGGER.info("try to get info without session");
try {
okApi.getGroupService().getUserGroupsV2();
Assert.fail("Method did not throw exception without session");
} catch (ApiException e) {
Assert.assertEquals("Session Is Required", ERROR_NO_SESSION, e.getApiErrorInfo().getErrorMessage());
}

LOGGER.info("session method throws a correct error");
}

@Test
public void testCountParameter() throws ApiException {
LOGGER.info("Check that the number of groups is the same as count");
int count = 5;

bindDefaultUserSession();
GroupGetUserGroupsV2Response groupGetUserGroupsV2Response = okApi.getGroupService().getUserGroupsV2(count);

Assert.assertEquals("the number of groups is not the same as count", groupGetUserGroupsV2Response.getGroups().size(), count);

LOGGER.info("the number of groups is the same as count");
}

}