hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ReducingOutputMessageBuilderTest.cpp
Go to the documentation of this file.
1 /*
2  * ReducingOutputMessageBuilderTest.cpp
3  *
4  * Created on: Jun 5, 2013
5  * Author: igor
6  */
7 
8 #include <gtest/gtest.h>
10 #include "HandlerMocks.hpp"
11 #include "TestUtils.hpp"
12 
13 using namespace HCE::reduce;
14 using namespace Poco;
15 using namespace std;
16 
17 using ::testing::_;
18 using ::testing::Return;
19 
20 class ReducingOutputMessageBuilderTest: public ::testing::Test{
21  protected:
22  virtual void SetUp(){
23  reducingExceptionsTranslator.assign(new ReducingExceptionsTranslatorMock());
24  }
25 
26  virtual void TearDown(){
27  reducingExceptionsTranslator.assign(NULL);
28  etalonOutputMessage.assign(NULL);
29  reducingOutputMessage.assign(NULL);
30  }
31 
32  static SharedPtr<ReducingExceptionsTranslatorMock> reducingExceptionsTranslator;
33  static SharedPtr<ReducingOutputMessage> etalonOutputMessage;
34  static SharedPtr<ReducingOutputMessage> reducingOutputMessage;
35 };
36 SharedPtr<ReducingExceptionsTranslatorMock>ReducingOutputMessageBuilderTest::
38 SharedPtr<ReducingOutputMessage>ReducingOutputMessageBuilderTest::etalonOutputMessage;
39 SharedPtr<ReducingOutputMessage>ReducingOutputMessageBuilderTest::reducingOutputMessage;
40 
41 
42 TEST_F(ReducingOutputMessageBuilderTest, buildOutputMessageFromJSON)
43 {
44  HCE::types::MessageType msgType = HCE::types::MessageType::mtSphinx;
45  string reducingResultJSON = "test";
46  int ttl = 7;
47 
48  etalonOutputMessage = buildEtalonFrom(msgType, ttl, reducingResultJSON);
49 
50  ReducingOutputMessageBuilder reducingOutputMessageBuilder(reducingExceptionsTranslator);
51 
52  reducingOutputMessage = reducingOutputMessageBuilder.build(msgType, ttl, reducingResultJSON);
53 
54  ASSERT_TRUE(isEqualReducingOutputMessage(*reducingOutputMessage.get(),
55  *etalonOutputMessage.get()));
56 }
57 
58 
59 TEST_F(ReducingOutputMessageBuilderTest, buildOutputMessageFromNotFoundByKeyException)
60 {
61  NotFoundByKeyException notFoundByKeyException("key 2 is wrong");
62  etalonOutputMessage = buildEtalonFrom(notFoundByKeyException);
63 
64  EXPECT_CALL(*reducingExceptionsTranslator.get(), translateToErrorCode(_))
65  .WillOnce(Return(INTERNAL_ERROR));
66  EXPECT_CALL(*reducingExceptionsTranslator.get(), translateToErrorMsg(_))
67  .WillOnce(Return(notFoundByKeyException.what()));
68 
69  ReducingOutputMessageBuilder reducingOutputMessageBuilder(reducingExceptionsTranslator);
70 
71  reducingOutputMessage = reducingOutputMessageBuilder.build(notFoundByKeyException);
72 
73  ASSERT_TRUE(isEqualReducingOutputMessage(*reducingOutputMessage.get(),
74  *etalonOutputMessage.get()));
75 }