+++ /dev/null
-/*
- * In Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- */
-package com.samsung.ci.basic.api;
-
-import org.apache.log4j.Logger;
-import org.iotivity.base.*;
-
-import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static java.util.EnumSet.of;
-import static java.util.stream.Collectors.toList;
-import static org.iotivity.base.OcPlatform.WELL_KNOWN_QUERY;
-
-/**
- * The type Cloud.
- *
- * @author Mail to: <A HREF="mailto:m.dalakov@samsung.com">Mikhail Dalakov</A>
- * @version 1.0
- * @file Cloud.java
- * @brief Base class for cloud used native lib
- * @date Created : 9/11/2017
- * @date Modified : 9/11/2017
- * @copyright In Samsung Ukraine R&D Center (SRK under a contract between)
- * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
- */
-public final class Cloud {
-
- private static final String IOTIVITY_HOST = AppConfigInit.getEnv().getRequiredProperty("iotivity.host");
- private static final String MODEL_NAME = AppConfigInit.getEnv().getRequiredProperty("iotivity.model.name");
- private static final String MODEL_NAME_KEY = AppConfigInit.getEnv().getRequiredProperty("iotivity.model.name.key");
- private static final String APP_NAME = AppConfigInit.getEnv().getRequiredProperty("iotivity.app.name");
- private static final String APP_NAME_KEY = AppConfigInit.getEnv().getRequiredProperty("iotivity.app.name.key");
- private static final Logger LOG = Logger.getLogger(Cloud.class);
-
- private Cloud() {
- }
-
- private static final Object LOCK = new Object();
- private static String uuid;
- private static Boolean isPostCompleted = false;
-
- private static class SignUpListener implements OcAccountManager.OnPostListener {
-
- private OcAccountManager manager;
-
- private void setManager(OcAccountManager manager) {
- this.manager = manager;
- }
-
- private static void setUuid(String s) {
- uuid = s;
- isPostCompleted = true;
- }
-
- @Override
- public void onPostFailed(Throwable t) {
- }
-
- @Override
- public void onPostCompleted(List<OcHeaderOption> arg0, OcRepresentation rep) {
- try {
- manager.signIn(rep.getValue("uid"), rep.getValue("accesstoken"), new OcAccountManager.OnPostListener() {
-
- public void onPostCompleted(List<OcHeaderOption> arg0, OcRepresentation arg1) {
- }
-
- public void onPostFailed(Throwable t) {
- }
- });
- setUuid(rep.getValue("uid"));
- } catch (OcException e) {
- LOG.error(e.getMessage(), e);
- }
- }
- }
-
- /**
- * Cloud signUp
- *
- * @param authcode the authcode
- * @param authprovider the authprovider
- * @return the string
- * @throws URISyntaxException the uri syntax exception
- * @throws OcException the oc exception
- * @throws InterruptedException the interrupted exception
- */
- public static String signUp(String authcode, String authprovider) throws URISyntaxException, OcException, InterruptedException {
- // This assumes the oic_svr_db_server.dat file is in the same location
- // as the SimpleServer.jar file
- String path = getPath();
-
- //By setting to "0.0.0.0", it binds to all available interfaces
- PlatformConfig platformConfig = new PlatformConfig(ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0",
- 0,
- QualityOfService.LOW, path + "/oic_svr_db_server.dat");
- OcPlatform.Configure(platformConfig);
- OcPlatform.setPropertyValue(PayloadType.DEVICE.getValue(), APP_NAME_KEY, APP_NAME);
- OcPlatform.setPropertyValue(PayloadType.DEVICE.getValue(), MODEL_NAME_KEY, MODEL_NAME);
- OcAccountManager manager = OcPlatform.constructAccountManagerObject(IOTIVITY_HOST, of(OcConnectivityType.CT_ADAPTER_TCP));
- SignUpListener signUpListener = new SignUpListener();
- signUpListener.setManager(manager);
-
- synchronized (LOCK) {
- uuid = null;
- isPostCompleted = false;
- manager.signUp(authprovider, authcode, signUpListener);
- final int timeout = 1000;
- while (!isPostCompleted) {
- LOCK.wait(timeout);
- }
- }
- return uuid;
- }
-
- /**
- * Get resources's uuids
- *
- * @return list of uuids
- * @throws URISyntaxException the uri syntax exception
- * @throws OcException the oc exception
- * @throws InterruptedException the interrupted exception
- */
- public static List<String> resources() throws URISyntaxException, OcException, InterruptedException {
- String path = getPath();
-
- PlatformConfig platformConfig =
- new PlatformConfig(ServiceType.IN_PROC, ModeType.CLIENT_SERVER, "0.0.0.0", 0,
- QualityOfService.LOW, path + "/oic_svr_db_server.dat");
- OcPlatform.Configure(platformConfig);
-
- OcPlatform.setPropertyValue(PayloadType.DEVICE.getValue(), APP_NAME_KEY, APP_NAME);
- OcPlatform.setPropertyValue(PayloadType.DEVICE.getValue(), MODEL_NAME_KEY, MODEL_NAME);
-
- final List<OcResource> resources = new ArrayList<>();
-
- OcPlatform.findResources(IOTIVITY_HOST, WELL_KNOWN_QUERY, of(OcConnectivityType.CT_ADAPTER_TCP), new OcPlatform.OnResourcesFoundListener() {
- @Override
- public void onResourcesFound(OcResource[] ocResources) {
- resources.addAll(Arrays.asList(ocResources));
- isPostCompleted = true;
- }
-
- @Override
- public void onFindResourcesFailed(Throwable throwable, String s) {
- isPostCompleted = true;
- }
- });
-
- synchronized (LOCK) {
- isPostCompleted = false;
-
- final int timeout = 1000;
- while (!isPostCompleted) {
- LOCK.wait(timeout);
- }
- }
-
- return resources.stream().map(OcResource::getServerId).collect(toList());
- }
-
- private static String getPath() throws URISyntaxException {
- String path = Cloud.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
- path = path.substring(0, path.lastIndexOf('/'));
- return path;
- }
-}
+++ /dev/null
-/*
- * In Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
- */
-package com.samsung.ci.test.useractions;
-
-import static com.samsung.ci.basic.api.Cloud.signUp;
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URISyntaxException;
-
-import org.iotivity.base.OcException;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.jupiter.api.Disabled;
-import org.junit.runner.RunWith;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-import io.restassured.response.Response;
-
-/**
- * The type Authorized using cloud test.
- *
- * @author Mail to: <A HREF="mailto:m.dalakov@samsung.com">Mikhail Dalakov</A>
- * @version 1.0
- * @file AuthorizedUsingCloudTest.java
- * @brief Authorized using cloud scenario
- * @date Created : 9/11/2017
- * @date Modified : 9/11/2017
- * @copyright In Samsung Ukraine R&D Center (SRK under a contract between)
- * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
- */
-@Disabled
-@Ignore
-@RunWith(SpringJUnit4ClassRunner.class)
-public class AuthorizedUsingCloudTest extends BasicUserAction {
-
- /**
- * Info.
- */
- @BeforeClass
- public static void info() {
- //@formatter:off
- log("Authorized using cloud scenario:\n"
- + "1. Create new user;\n"
- + "2. Login as new user;\n"
- + "3. Get auth code;\n"
- + "4. Get user uuid from Cloud\n"
- + "5. Create IoT user with uuid from Cloud\n"
- + "6. Logout new user\n"
- + "7. Login as admin\n"
- + "8. Delete IoTCloud User\n"
- + "9. Delete new DSM user\n"
- + "10. Logout\n");
- //@formatter:on
- }
-
- /**
- * Positive case
- * 1. Create new DSM user "userApiIntegrationTest"
- * 2. Login as new user
- * 3. Get auth code
- * 4. Get user uuid from Cloud
- * 5. Create IoT user with uuid from Cloud
- * 6. Logout new user
- * 7. Login as admin
- * 8. Delete IoTCloud User
- * 9. Delete new DSM user
- * 10. Logout
- *
- * @throws URISyntaxException the uri syntax exception
- * @throws OcException the oc exception
- * @throws InterruptedException the interrupted exception
- */
- @Test
- public void testAuthorizedUsingCloud() throws URISyntaxException, OcException, InterruptedException {
- createNewUser();
- loginNewUser();
- String authcode = getAuthCode(ADMIN_EMAIL, ADMIN_PASSWORD);
- String uuid = signUp(authcode, "Samsung");
- assertNotNull(uuid);
- createIoTUser(USER_EMAIL, uuid);
- logoutNewUser();
- Response resp = loginAdmin();
- deleteIoTUser(uuid);
- deleteNewUserIfAdmin(resp.getCookie("JSESSIONID"));
- logoutAdmin();
- }
-
-}