You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by ve...@apache.org on 2012/06/01 14:20:06 UTC

svn commit: r1345107 - in /incubator/etch/trunk/binding-cpp/runtime: include/serialization/ src/main/ src/main/serialization/ src/test/ src/test/serialization/

Author: veithm
Date: Fri Jun  1 12:20:06 2012
New Revision: 1345107

URL: http://svn.apache.org/viewvc?rev=1345107&view=rev
Log:
ETCH-184 Implementation of EtchAuthenticationExceptionSerializer

Change-Id: Ieafb65cb34a65fec7db50250918689f9509eea1a

Added:
    incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchAuthenticationExceptionSerializer.h
    incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp
    incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp
Modified:
    incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
    incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt

Added: incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchAuthenticationExceptionSerializer.h
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchAuthenticationExceptionSerializer.h?rev=1345107&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchAuthenticationExceptionSerializer.h (added)
+++ incubator/etch/trunk/binding-cpp/runtime/include/serialization/EtchAuthenticationExceptionSerializer.h Fri Jun  1 12:20:06 2012
@@ -0,0 +1,66 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ETCHAUTHENTICATIONEXCEPTIONSERIALIZER_H__
+#define __ETCHAUTHENTICATIONEXCEPTIONSERIALIZER_H__
+
+#include "common/EtchString.h"
+#include "common/EtchAuthenticationException.h"
+#include "serialization/EtchImportExportHelper.h"
+#include "serialization/EtchStructValue.h"
+#include "serialization/EtchType.h"
+#include "serialization/EtchField.h"
+#include "serialization/EtchClass2TypeMap.h"
+#include "serialization/EtchValidatorString.h"
+
+
+class EtchAuthenticationExceptionSerializer : public EtchImportExportHelper {
+public:
+
+  /**
+   * Constructor
+   */
+  EtchAuthenticationExceptionSerializer(EtchType* type, EtchField* field);
+
+  /**
+   * Destructor
+   */
+  virtual ~EtchAuthenticationExceptionSerializer();
+
+  virtual status_t exportValue(EtchValueFactory* vf, capu::SmartPointer<EtchObject> value, EtchStructValue*& result);
+
+  virtual status_t importValue(EtchStructValue* value, capu::SmartPointer<EtchObject> &result);
+
+
+  /**
+   * Defines custom fields in the value factory so that the importer can find them.
+   * @param type
+   * @param collection
+   */
+  static status_t Init(EtchType* type, EtchClass2TypeMap* class2type);
+
+private:
+
+  EtchField mField;
+  EtchType* mType;
+  const static EtchString FIELD_NAME;
+
+};
+
+#endif /* ETCHAUTHENTICATIONEXCEPTIONSERIALIZER_H */
+

Modified: incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt?rev=1345107&r1=1345106&r2=1345107&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/CMakeLists.txt Fri Jun  1 12:20:06 2012
@@ -89,6 +89,7 @@ SET(MAIN_INCLUDES
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchListSerializer.h
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchValidatorRuntimeException.h
     ${PROJECT_SOURCE_DIR}/include/serialization/EtchRuntimeExceptionSerializer.h
+    ${PROJECT_SOURCE_DIR}/include/serialization/EtchAuthenticationExceptionSerializer.h
     ${PROJECT_SOURCE_DIR}/include/util/EtchUtil.h
     )
 
@@ -138,6 +139,7 @@ SET(MAIN_SOURCES
     serialization/EtchListSerializer.cpp
     serialization/EtchValidatorRuntimeException.cpp
     serialization/EtchRuntimeExceptionSerializer.cpp
+    serialization/EtchAuthenticationExceptionSerializer.cpp
     util/EtchUtil.cpp
     )
 

Added: incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp?rev=1345107&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/main/serialization/EtchAuthenticationExceptionSerializer.cpp Fri Jun  1 12:20:06 2012
@@ -0,0 +1,80 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "serialization/EtchAuthenticationExceptionSerializer.h"
+
+const EtchString EtchAuthenticationExceptionSerializer::FIELD_NAME("msg");
+
+EtchAuthenticationExceptionSerializer::EtchAuthenticationExceptionSerializer(EtchType* type, EtchField* field)
+: mField(*field), mType(type) {
+
+}
+
+EtchAuthenticationExceptionSerializer::~EtchAuthenticationExceptionSerializer() {
+
+}
+
+status_t EtchAuthenticationExceptionSerializer::importValue(EtchStructValue* value, capu::SmartPointer<EtchObject> &result) {
+  if (value == NULL) {
+    return ETCH_EINVAL;
+  } else if (!value->isType(mType)) {
+    return ETCH_EINVAL;
+  }
+
+  capu::SmartPointer<EtchObject> tmp;
+  if (value->get(mField, &tmp) != ETCH_OK)
+    return ETCH_ERROR;
+
+  EtchString str = *((EtchString*) tmp.get());
+  result = new EtchAuthenticationException(str);
+  return ETCH_OK;
+}
+
+status_t EtchAuthenticationExceptionSerializer::exportValue(EtchValueFactory* vf, capu::SmartPointer<EtchObject> value, EtchStructValue*& result) {
+  if ((value.get() == NULL) || (vf == NULL))
+    return ETCH_EINVAL;
+  if (value->getObjectType() != EtchAuthenticationException::TYPE())
+    return ETCH_EINVAL;
+  result = new EtchStructValue(mType, vf);
+  EtchString *str = new EtchString(((EtchAuthenticationException*) value.get())->getErrorMessage());
+  if (result->put(mField, str) != ETCH_OK)
+    return ETCH_ERROR;
+
+  return ETCH_OK;
+}
+
+status_t EtchAuthenticationExceptionSerializer::Init(EtchType* type, EtchClass2TypeMap* class2type) {
+  status_t result;
+  EtchField field_ptr;
+  result = type->getField(FIELD_NAME, &field_ptr);
+  if (result != ETCH_OK)
+    return result;
+  class2type->put(EtchAuthenticationException::TYPE(), type);
+  type->setComponentType(EtchAuthenticationException::TYPE());
+  //set the import export helper
+  type->setImportExportHelper(new EtchAuthenticationExceptionSerializer(type, &field_ptr));
+  capu::SmartPointer<EtchValidator> tmp;
+  result = EtchValidatorString::Get(0, tmp);
+  if (result != ETCH_OK)
+    return result;
+  result = type->putValidator(field_ptr, tmp);
+  if (result != ETCH_OK)
+    return result;
+  type->lock();
+  return ETCH_OK;
+}
\ No newline at end of file

Modified: incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt?rev=1345107&r1=1345106&r2=1345107&view=diff
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt (original)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/CMakeLists.txt Fri Jun  1 12:20:06 2012
@@ -70,6 +70,7 @@ add_executable (etch-cpp-test
     serialization/EtchListSerializerTest.cpp
     serialization/EtchValidatorRuntimeExceptionTest.cpp
     serialization/EtchRuntimeExceptionSerializerTest.cpp
+    serialization/EtchAuthenticationExceptionSerializerTest.cpp
     util/EtchUtilTest.cpp
     ${GTEST}/src/gtest-all.cc
     ${GMOCK}/src/gmock-all.cc

Added: incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp?rev=1345107&view=auto
==============================================================================
--- incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp (added)
+++ incubator/etch/trunk/binding-cpp/runtime/src/test/serialization/EtchAuthenticationExceptionSerializerTest.cpp Fri Jun  1 12:20:06 2012
@@ -0,0 +1,166 @@
+/* $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+
+#include "gtest/gtest.h"
+#include "gmock/gmock.h"
+#include "serialization/EtchValueFactory.h"
+#include "serialization/EtchAuthenticationExceptionSerializer.h"
+
+class MockValueFactory3 : public virtual EtchValueFactory {
+public:
+
+  ~MockValueFactory3() {
+
+  }
+  MOCK_METHOD2(getType, status_t(capu::uint32_t id, EtchType*& result));
+
+  MOCK_METHOD2(getType, status_t(EtchString& name, EtchType*& result));
+
+  MOCK_METHOD1(addType, status_t(EtchType* type));
+
+  MOCK_METHOD0(lockDynamicTypes, status_t());
+
+  MOCK_METHOD0(unlockDynamicTypes, status_t());
+
+  MOCK_METHOD2(getMessageId, status_t(EtchMessage* msg, capu::int64_t &result));
+
+  MOCK_METHOD2(setMessageId, status_t(EtchMessage* msg, capu::int64_t msgid));
+
+  MOCK_METHOD0(get_mf__messageId, EtchField());
+
+  MOCK_METHOD2(getInReplyTo, status_t(EtchMessage* msg, capu::int64_t &result));
+
+  MOCK_METHOD2(setInReplyTo, status_t(EtchMessage* msg, capu::int64_t msgid));
+
+  MOCK_METHOD0(get_mf__inReplyTo, EtchField());
+
+  MOCK_METHOD2(importCustomValue, status_t(EtchStructValue* _struct, capu::SmartPointer<EtchObject> &result));
+
+  MOCK_METHOD2(exportCustomValue, status_t(capu::SmartPointer<EtchObject> value, EtchStructValue*& result));
+
+  MOCK_METHOD0(get_mt__exception, EtchType*());
+
+  MOCK_METHOD2(getCustomStructType, status_t(capu::int32_t c, EtchType *& type));
+
+  EtchLevel getLevel() {
+    return LEVEL_FULL;
+  }
+
+  MOCK_METHOD1(setLevel, EtchLevel(EtchLevel level));
+
+};
+
+TEST(EtchAuthenticationExceptionSerializationTest, initTest) {
+  EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+  EtchString typeName("type1");
+  EtchType* type = new EtchType(10, typeName);
+  EtchType* result;
+  EXPECT_TRUE(EtchAuthenticationExceptionSerializer::Init(type, c2type) == ETCH_OK);
+  c2type->get(EtchAuthenticationException::TYPE(), &result);
+
+  //check the added type to class to type matching
+  EXPECT_TRUE(type == result);
+  //check the initialized component type
+  EXPECT_TRUE(type->getComponentType() == EtchAuthenticationException::TYPE());
+
+  //to check the initialized validator
+  capu::SmartPointer<EtchValidator> validator;
+  EtchField field;
+  typeName = "msg";
+  type->getField(typeName, &field);
+  //check validator
+  type->getValidator(field, validator);
+  capu::SmartPointer<EtchValidator> val;
+  EtchValidatorString::Get(0, val);
+  EXPECT_TRUE(validator == val);
+  delete type;
+  delete c2type;
+}
+
+TEST(EtchAuthenticationExceptionSerializationTest, exportTest) {
+  EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+  EtchString typeName("type1");
+  EtchString message("message");
+  EtchValueFactory* factory = new MockValueFactory3();
+  EtchType* type = new EtchType(10, typeName);
+  capu::SmartPointer<EtchObject> object = new EtchAuthenticationException(message);
+  capu::SmartPointer<EtchObject> object2 = new EtchInt32();
+  capu::SmartPointer<EtchObject> object3;
+  EtchStructValue* result;
+  //initialize the serializer
+  EXPECT_TRUE(EtchAuthenticationExceptionSerializer::Init(type, c2type) == ETCH_OK);
+  EtchImportExportHelper* test = type->getImportExportHelper();
+  //check with invalid values
+  EXPECT_TRUE(test->exportValue(NULL, NULL, result) == ETCH_EINVAL);
+  EXPECT_TRUE(test->exportValue(NULL, object, result) == ETCH_EINVAL);
+  EXPECT_TRUE(test->exportValue(factory, NULL, result) == ETCH_EINVAL);
+  EXPECT_TRUE(test->exportValue(factory, object2, result) == ETCH_EINVAL);
+  //export values
+  EXPECT_TRUE(test->exportValue(factory, object, result) == ETCH_OK);
+
+  //check it has been correctly serialized or not
+  EtchString str("msg");
+  EtchField field;
+
+  //get the fields
+  EXPECT_TRUE(type->getField(str, &field) == ETCH_OK);
+  //use the field to get the serialized value
+  EXPECT_TRUE(result->get(field, &object3) == ETCH_OK);
+  capu::SmartPointer<EtchString> serialized_exp = capu::smartpointer_cast<EtchString > (object3);
+  //check the assigned type
+  EXPECT_TRUE(type->getComponentType() == EtchAuthenticationException::TYPE());
+  //check the serialized value
+  EXPECT_TRUE(serialized_exp->equals(&message));
+
+  delete c2type;
+  delete factory;
+  delete type;
+  delete result;
+}
+
+TEST(EtchAuthenticationExceptionSerializationTest, importTest) {
+  EtchClass2TypeMap* c2type = new EtchClass2TypeMap();
+  EtchString typeName("type1");
+  EtchString message("message");
+  EtchValueFactory* factory = new MockValueFactory3();
+  EtchType* type = new EtchType(10, typeName);
+  capu::SmartPointer<EtchObject> object = new EtchAuthenticationException(message);
+  EtchStructValue* structValue;
+  //initialize the serializer
+  EXPECT_TRUE(EtchAuthenticationExceptionSerializer::Init(type, c2type) == ETCH_OK);
+  //get the serializer
+  EtchImportExportHelper* test = type->getImportExportHelper();
+  //export values
+  EXPECT_TRUE(test->exportValue(factory, object, structValue) == ETCH_OK);
+
+  //UPPER PART IS USED FOR GENERATING EXAMPLE INPUT VALUE FOR IMPORT
+  capu::SmartPointer<EtchObject> result;
+  //IMPORT TEST
+  EXPECT_TRUE(test->importValue(NULL, result) == ETCH_EINVAL);
+  EXPECT_TRUE(test->importValue(structValue, result) == ETCH_OK);
+
+  capu::SmartPointer<EtchAuthenticationException> imported_exp = capu::smartpointer_cast<EtchAuthenticationException > (result);
+  //check the imported value
+  EXPECT_TRUE(imported_exp->getErrorMessage().equals(&message));
+  delete c2type;
+  delete factory;
+  delete type;
+  delete structValue;
+}