You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by bp...@apache.org on 2015/10/29 08:28:01 UTC

celix git commit: CELIX-263: add test for discovery_configured/rsa_http

Repository: celix
Updated Branches:
  refs/heads/develop c97fc5b82 -> b15ffbac1


CELIX-263: add test for discovery_configured/rsa_http


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/b15ffbac
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/b15ffbac
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/b15ffbac

Branch: refs/heads/develop
Commit: b15ffbac1a9f6c167396606679b0f07702e6acfa
Parents: c97fc5b
Author: Bjoern Petri <bp...@apache.org>
Authored: Thu Oct 29 08:27:23 2015 +0100
Committer: Bjoern Petri <bp...@apache.org>
Committed: Thu Oct 29 08:27:23 2015 +0100

----------------------------------------------------------------------
 .../remote_service_admin_http/CMakeLists.txt    |   6 +
 .../private/test/CMakeLists.txt                 |  46 ++++++++
 .../private/test/client.properties.in           |   9 ++
 .../private/test/rsa_client_server_tests.cpp    | 112 +++++++++++++++++++
 .../private/test/run_tests.cpp                  |   9 ++
 .../private/test/server.properties.in           |   8 ++
 6 files changed, 190 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/b15ffbac/remote_services/remote_service_admin_http/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/CMakeLists.txt b/remote_services/remote_service_admin_http/CMakeLists.txt
index a147a37..58a8fd6 100644
--- a/remote_services/remote_service_admin_http/CMakeLists.txt
+++ b/remote_services/remote_service_admin_http/CMakeLists.txt
@@ -46,4 +46,10 @@ if (RSA_REMOTE_SERVICE_ADMIN_HTTP)
 	install_bundle(remote_service_admin_http)
 
 	target_link_libraries(remote_service_admin_http celix_framework ${CURL_LIBRARIES} ${UUID})
+
+	if (ENABLE_TESTING)
+             find_package(CppUTest REQUIRED)
+	     include_directories(${CPPUTEST_INCLUDE_DIR})
+	     add_subdirectory(private/test)
+         endif()
 endif (RSA_REMOTE_SERVICE_ADMIN_HTTP)

http://git-wip-us.apache.org/repos/asf/celix/blob/b15ffbac/remote_services/remote_service_admin_http/private/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/CMakeLists.txt b/remote_services/remote_service_admin_http/private/test/CMakeLists.txt
new file mode 100644
index 0000000..479ac62
--- /dev/null
+++ b/remote_services/remote_service_admin_http/private/test/CMakeLists.txt
@@ -0,0 +1,46 @@
+#
+# Licensed under Apache License v2. See LICENSE for more information.
+#
+
+
+include_directories(
+    ${PROJECT_SOURCE_DIR}/framework/public/include
+    ${PROJECT_SOURCE_DIR}/utils/public/include
+    ${PROJECT_SOURCE_DIR}/utils/public/include
+    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/public/include
+    ${PROJECT_SOURCE_DIR}/remote_services/examples/calculator_service/public/include
+    bundle
+)
+
+
+SET(CMAKE_SKIP_BUILD_RPATH  FALSE) #TODO needed?
+SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) #TODO needed?
+SET(CMAKE_INSTALL_RPATH "${PROJECT_BINARY_DIR}/framework" "${PROJECT_BINARY_DIR}/utils")
+
+add_executable(test_rsa_http
+    run_tests.cpp
+    rsa_client_server_tests.cpp
+
+    ${PROJECT_SOURCE_DIR}/remote_services/remote_service_admin/private/src/endpoint_description.c
+)
+target_link_libraries(test_rsa_http celix_framework celix_utils ${CURL_LIBRARIES} ${CPPUTEST_LIBRARY})
+
+get_property(rsa_bundle_file TARGET remote_service_admin_http PROPERTY BUNDLE)
+get_property(calc_bundle_file TARGET calculator PROPERTY BUNDLE)
+get_property(calculator_shell_bundle_file TARGET calculator_shell PROPERTY BUNDLE)
+get_property(discovery_configured_bundle_file TARGET discovery_configured PROPERTY BUNDLE)
+get_property(topology_manager_bundle_file TARGET topology_manager PROPERTY BUNDLE)
+get_property(calc_proxy_bundle_file TARGET org.apache.celix.calc.api.Calculator_proxy PROPERTY BUNDLE)
+get_property(calc_endpoint_bundle_file TARGET  org.apache.celix.calc.api.Calculator_endpoint PROPERTY BUNDLE)
+
+get_filename_component(client_endpoints @calc_proxy_bundle_file@ DIRECTORY)
+get_filename_component(server_endpoints @calc_endpoint_bundle_file@ DIRECTORY)
+
+configure_file(client.properties.in client.properties @ONLY)
+configure_file(server.properties.in server.properties @ONLY)
+
+add_dependencies(test_rsa_http remote_service_admin_http calculator org.apache.celix.calc.api.Calculator_proxy org.apache.celix.calc.api.Calculator_endpoint)
+ 
+add_test(NAME run_test_rsa_http COMMAND test_rsa_http)
+SETUP_TARGET_FOR_COVERAGE(test_rsa_http_cov test_rsa_http ${CMAKE_BINARY_DIR}/coverage/test_rsa_http/test_rsa_http)
+

http://git-wip-us.apache.org/repos/asf/celix/blob/b15ffbac/remote_services/remote_service_admin_http/private/test/client.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/client.properties.in b/remote_services/remote_service_admin_http/private/test/client.properties.in
new file mode 100644
index 0000000..9a734f8
--- /dev/null
+++ b/remote_services/remote_service_admin_http/private/test/client.properties.in
@@ -0,0 +1,9 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calculator_shell_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@ @tst_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+ENDPOINTS=@client_endpoints@
+RSA_PORT=50881
+DISCOVERY_CFG_SERVER_PORT=50991
+DISCOVERY_CFG_POLL_ENDPOINTS=http://127.0.0.1:50992/org.apache.celix.discovery.configured
+org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheClient
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/b15ffbac/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp b/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp
new file mode 100644
index 0000000..7cf2afd
--- /dev/null
+++ b/remote_services/remote_service_admin_http/private/test/rsa_client_server_tests.cpp
@@ -0,0 +1,112 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include <remote_constants.h>
+#include <constants.h>
+#include "CppUTest/CommandLineTestRunner.h"
+#include "../../../examples/calculator_service/public/include/calculator_service.h"
+
+extern "C" {
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+
+#include "celix_launcher.h"
+#include "framework.h"
+#include "remote_service_admin.h"
+#include "calculator_service.h"
+
+    static framework_pt serverFramework = NULL;
+    static bundle_context_pt serverContext = NULL;
+
+    static framework_pt clientFramework = NULL;
+    static bundle_context_pt clientContext = NULL;
+
+    static void setupFm(void) {
+        int rc = 0;
+        bundle_pt bundle = NULL;
+
+        //server
+        rc = celixLauncher_launch("server.properties", &serverFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(serverFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &serverContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+
+        //client
+        rc = celixLauncher_launch("client.properties", &clientFramework);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        bundle = NULL;
+        rc = framework_getFrameworkBundle(clientFramework, &bundle);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+        rc = bundle_getContext(bundle, &clientContext);
+        CHECK_EQUAL(CELIX_SUCCESS, rc);
+    }
+
+    static void teardownFm(void) {
+        celixLauncher_stop(serverFramework);
+        celixLauncher_waitForShutdown(serverFramework);
+        celixLauncher_destroy(serverFramework);
+
+        celixLauncher_stop(clientFramework);
+        celixLauncher_waitForShutdown(clientFramework);
+        celixLauncher_destroy(clientFramework);
+
+        serverContext = NULL;
+        serverFramework = NULL;
+        clientContext = NULL;
+        clientFramework = NULL;
+    }
+
+    static void test1(void) {
+        celix_status_t status;
+        service_reference_pt ref = NULL;
+        calculator_service_pt calcService = NULL;
+        usleep(2000000); //TODO use tracker
+
+        status = bundleContext_getServiceReference(clientContext, (char *)CALCULATOR_SERVICE, &ref);
+        CHECK_EQUAL(CELIX_SUCCESS, status);
+        CHECK(ref != NULL);
+
+        status = bundleContext_getService(clientContext, ref, (void **)&calcService);
+        CHECK_EQUAL(CELIX_SUCCESS, status);
+        CHECK(calcService != NULL);
+
+        double result = 0;
+        status = calcService->add(calcService->calculator, 2.0, 5.0, &result);
+        CHECK_EQUAL(CELIX_SUCCESS, status);
+        CHECK_EQUAL(7.0, result);
+
+        bool ungetResult = false;
+        bundleContext_ungetService(clientContext, ref, NULL);
+        bundleContext_ungetServiceReference(clientContext, ref);
+    }
+
+}
+
+
+TEST_GROUP(RsaHttpClientServerTests) {
+    void setup() {
+        setupFm();
+    }
+
+    void teardown() {
+        teardownFm();
+    }
+};
+
+TEST(RsaHttpClientServerTests, Test1) {
+    test1();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/b15ffbac/remote_services/remote_service_admin_http/private/test/run_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/run_tests.cpp b/remote_services/remote_service_admin_http/private/test/run_tests.cpp
new file mode 100644
index 0000000..c5e960c
--- /dev/null
+++ b/remote_services/remote_service_admin_http/private/test/run_tests.cpp
@@ -0,0 +1,9 @@
+/*
+ * Licensed under Apache License v2. See LICENSE for more information.
+ */
+#include <CppUTest/TestHarness.h>
+#include "CppUTest/CommandLineTestRunner.h"
+
+int main(int argc, char** argv) {
+    return RUN_ALL_TESTS(argc, argv);
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/celix/blob/b15ffbac/remote_services/remote_service_admin_http/private/test/server.properties.in
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/test/server.properties.in b/remote_services/remote_service_admin_http/private/test/server.properties.in
new file mode 100644
index 0000000..a6b736e
--- /dev/null
+++ b/remote_services/remote_service_admin_http/private/test/server.properties.in
@@ -0,0 +1,8 @@
+cosgi.auto.start.1=@rsa_bundle_file@ @calc_bundle_file@ @discovery_configured_bundle_file@ @topology_manager_bundle_file@
+LOGHELPER_ENABLE_STDOUT_FALLBACK=true
+ENDPOINTS=@server_endpoints@
+RSA_PORT=50882
+DISCOVERY_CFG_SERVER_PORT=50992
+org.osgi.framework.storage.clean=onFirstInit
+org.osgi.framework.storage=.cacheServer
+DISCOVERY_CFG_POLL_INTERVAL=1
\ No newline at end of file