Пример #1
0
/* ****************************************************************************
*
* shortPath - 
*/
TEST(Convenience, shortPath)
{
  ConnectionInfo  ci1("ngsi9", "GET", "1.1");
  ConnectionInfo  ci2("ngsi10", "GET", "1.1");
  ConnectionInfo  ci3("ngsi8", "GET", "1.1");
  ConnectionInfo  ci4("ngsi10/nada", "GET", "1.1");
  std::string     out;
  const char*     outfile1 = "ngsi.convenience.shortPath.postponed.xml";
  const char*     outfile2 = "ngsi.convenience.shortPath2.postponed.xml";
  const char*     outfile3 = "ngsi.convenience.shortPath3.postponed.xml";
  const char*     outfile4 = "ngsi.convenience.shortPath4.postponed.xml";

  utInit();

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  out = restService(&ci1, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  out = restService(&ci2, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  out = restService(&ci3, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'";
  out = restService(&ci4, restServiceV);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* put - 
*/
TEST(putSubscriptionConvOp, put)
{
  ConnectionInfo ci1("/ngsi10/contextSubscriptions/012345678901234567890123",  "DELETE", "1.1");
  ConnectionInfo ci2("/ngsi10/contextSubscriptions/111222333444555666777888",  "PUT",    "1.1");
  ConnectionInfo ci3("/ngsi10/contextSubscriptions/111222333444555666777881",  "PUT",    "1.1");
  ConnectionInfo ci4("/ngsi10/contextSubscriptions/012345678901234567890123",  "XVERB",  "1.1");
  const char*    infile       = "ngsi10.updateContextSubscriptionRequest.subscriptionNotFound.valid.xml";
  const char*    outfile1     = "ngsi10.unsubscribeContextResponse.putSubscriptionConvOp.notFound.valid.xml";
  const char*    outfile2     = "ngsi10.updateContextSubscriptionResponse.putSubscriptionConvOp.notFound.valid.xml";
  const char*    outfile3     = "ngsi10.updateContextSubscriptionResponse.putSubscriptionConvOp.unmatchingSubscriptionId.valid.xml";
  std::string    out;

  utInit();

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  ci1.outFormat    = XML;
  ci1.inFormat     = XML;
  ci1.payload      = NULL;
  ci1.payloadSize  = 0;
  out              = restService(&ci1, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());
  

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci2.outFormat    = XML;
  ci2.inFormat     = XML;
  ci2.payload      = testBuf;
  ci2.payloadSize  = strlen(testBuf);
  out              = restService(&ci2, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile)) << "Error getting test data from '" << infile << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  ci3.outFormat    = XML;
  ci3.inFormat     = XML;
  ci3.payload      = testBuf;
  ci3.payloadSize  = strlen(testBuf);
  out              = restService(&ci3, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  ci4.outFormat    = XML;
  ci4.inFormat     = XML;
  ci4.payload      = NULL;
  ci4.payloadSize  = 0;
  out              = restService(&ci4, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow",       ci4.httpHeader[0]);
  EXPECT_EQ("PUT, DELETE", ci4.httpHeaderValue[0]);

  utExit();
}
Пример #3
0
/* ****************************************************************************
*
* parseError - 
*/
TEST(xmlRequest, parseError)
{
  ConnectionInfo  ci("/ngsi/registerContext", "POST", "1.1");
  ConnectionInfo  ci2("/ngsi/registerContext123", "POST", "1.1");
  ConnectionInfo  ci3("/ngsi/registerContext", "POST", "1.1");
  ConnectionInfo  ci4("/version", "POST", "1.1");
  ParseData       parseData;
  const char*     infile1  = "ngsi9.registerContextRequest.parseError.invalid.xml"; 
  const char*     infile2  = "ngsi9.registerContextRequest.ok.valid.xml"; 
  const char*     infile3  = "ngsi9.registerContextRequest.errorInFirstLine.invalid.xml";
  const char*     outfile1 = "orion.error.parseError.valid.xml";
  const char*     outfile2 = "orion.error.noRequestTreatingObjectFound.valid.xml";
  const char*     outfile3 = "orion.error.parseError.valid.xml";
  const char*     outfile4 = "ngsi9.registerContextResponse.invalidPayload.valid.xml";
  std::string     out;

  utInit();

  // Parse Error
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile1)) << "Error getting test data from '" << infile1 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  ci.inFormat  = XML;
  ci.outFormat = XML;
  out  = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  // Request not found
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci2.inFormat  = XML;
  ci2.outFormat = XML;
  out  = xmlTreat(testBuf, &ci2, &parseData, (RequestType) (RegisterContext + 1000), "registerContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  // Error in first line '<?xml version="1.0" encoding="UTF-8"?>'
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile3)) << "Error getting test data from '" << infile3 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";
  ci3.inFormat  = XML;
  ci3.outFormat = XML;
  out  = xmlTreat(testBuf, &ci3, &parseData, RegisterContext, "registerContextRequest", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  // Payload word differs
  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'";
  ci.inFormat  = XML;
  ci.outFormat = XML;
  out  = xmlTreat(testBuf, &ci, &parseData, RegisterContext, "discovery", NULL);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
Пример #4
0
void TestCellInfo::TestGetWeighting()
{
    ComparisonContext cContext;
    CCellInfo ci1(1,3,5,7,L"", true,0);
    CCellInfo ci2(2,4,6,8,L"", true,0);

    assertTest(ci1.GetWeightingWith(&cContext, ci2) == CTWS_WHITESPACE_SCORE);
    assertTest(!ci1.DidFuzzyMatch());

    CCellInfo ci3(1,1,4,4,L"fishes", false,0);
    CCellInfo ci4(1,1,4,4,L"fishes", false,0);
    assertTest(ci3.GetWeightingWith(&cContext, ci4) == 1.0);
    assertTest(ci3.DidFuzzyMatch());

}
/* ****************************************************************************
*
* error - 
*/
TEST(badVerbAllFour, error)
{
  ConnectionInfo ci1("/ngsi10/contextEntities/123",  "PUST", "1.1");
  ConnectionInfo ci2("/ngsi10/contextEntities",      "PUST", "1.1");
  ConnectionInfo ci3("/ngsi10/",                     "PUST", "1.1");
  ConnectionInfo ci4("/ngsi10/1/2/3/4",              "PUST", "1.1");
  const char*    outfile1 = "orion.serviceNotRecognized.valid.xml";
  const char*    outfile2 = "orion.serviceNotRecognized2.valid.xml";
  std::string    out;

  utInit();

  ci1.apiVersion = "v1";
  out = restService(&ci1, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci1.httpHeader[0]);
  EXPECT_EQ("POST, GET, PUT, DELETE", ci1.httpHeaderValue[0]);

  ci2.apiVersion = "v1";
  out = restService(&ci2, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci2.httpHeader[0]);
  EXPECT_EQ("POST, GET, PUT, DELETE", ci2.httpHeaderValue[0]);

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";
  ci3.apiVersion = "v1";
  out = restService(&ci3, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile2)) << "Error getting test data from '" << outfile2 << "'";
  ci4.apiVersion = "v1";
  out = restService(&ci4, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());

  utExit();
}
/* ****************************************************************************
*
* put - 
*/
TEST(putAvailabilitySubscriptionConvOp, put)
{
  ConnectionInfo ci1("/ngsi9/contextAvailabilitySubscriptions",  "POST", "1.1");
  ConnectionInfo ci2("/ngsi9/contextAvailabilitySubscriptions",  "GET",  "1.1");
  ConnectionInfo ci3("/ngsi9/contextAvailabilitySubscriptions/111222333444555666777888",  "PUT",     "1.1");
  ConnectionInfo ci4("/ngsi9/contextAvailabilitySubscriptions/111222333444555666777888",  "DELETE",  "1.1");
  ConnectionInfo ci5("/ngsi9/contextAvailabilitySubscriptions/111222333444555666777881",  "PUT",     "1.1");
  ConnectionInfo ci6("/ngsi9/contextAvailabilitySubscriptions/012345678901234567890123",  "XVERB",   "1.1");
  const char*    infile1      = "ngsi9.subscribeContextAvailabilityRequest.ok.valid.xml";
  const char*    infile2      = "ngsi9.updateContextAvailabilitySubscriptionRequest.withSubId.valid.xml";
  const char*    outfile1     = "ngsi9.subscribeContextAvailabilityResponse.ok.middle.xml";
  const char*    outfile3     = "ngsi9.updateContextAvailabilitySubscriptionResponse.putAvailabilitySubscriptionConvOp.notFound.valid.xml";
  const char*    outfile4     = "ngsi9.unsubscribeContextAvailabilityResponse.putAvailabilitySubscriptionConvOp.notFound2.valid.xml";
  const char*    outfile5     = "ngsi9.updateContextAvailabilitySubscriptionResponse.putAvailabilitySubscriptionConvOp.unmatchingSubscriptionId.valid.xml";
  std::string    out;

  utInit();

  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile1)) << "Error getting test data from '" << infile1 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile1)) << "Error getting test data from '" << outfile1 << "'";

  ci1.payload      = testBuf;
  ci1.payloadSize  = strlen(testBuf);
  out              = restService(&ci1, rs);

  char* outStart   = (char*) out.c_str();
  // Remove last char in expectedBuf
  expectedBuf[strlen(expectedBuf) - 1] = 0;

  // Shorten'out' to be of same length as expectedBuf
  outStart[strlen(expectedBuf)]    = 0;
  EXPECT_STREQ(expectedBuf, out.c_str());


  out = restService(&ci2, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci2.httpHeader[0]);
  EXPECT_EQ("POST",  ci2.httpHeaderValue[0]);


  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile3)) << "Error getting test data from '" << outfile3 << "'";

  ci3.payload      = testBuf;
  ci3.payloadSize  = strlen(testBuf);
  out              = restService(&ci3, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile4)) << "Error getting test data from '" << outfile4 << "'";
  out = restService(&ci4, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  EXPECT_EQ("OK", testDataFromFile(testBuf, sizeof(testBuf), infile2)) << "Error getting test data from '" << infile2 << "'";
  EXPECT_EQ("OK", testDataFromFile(expectedBuf, sizeof(expectedBuf), outfile5)) << "Error getting test data from '" << outfile5 << "'";
  ci5.payload      = testBuf;
  ci5.payloadSize  = strlen(testBuf);
  out              = restService(&ci5, rs);
  EXPECT_STREQ(expectedBuf, out.c_str());


  out = restService(&ci6, rs);
  EXPECT_EQ("", out);
  EXPECT_EQ("Allow", ci6.httpHeader[0]);
  EXPECT_EQ("PUT, DELETE", ci6.httpHeaderValue[0]);

  utExit();
}
Пример #7
0
void drive_resolve_primitive()
{


    const char* env = getenv("PEGASUS_HOME");
    String repositoryDir(env);
    repositoryDir.append("/repository");
    //String repositoryDir("c:/pegasus-cvs/pegasus/repository");
    CIMNamespaceName _ns("root/cimv2");
    CIMRepository *_rep = new CIMRepository(repositoryDir);
    RepositoryQueryContext _query(_ns, _rep);
    RepositoryQueryContext _query1(_ns, _rep);
    try {
        const CQLIdentifier _Id1(String("CIM_OperatingSystem"));

        _query.insertClassPath(_Id1);

        const CIMName _cimName(String("CIM_OperatingSystem"));

        CIMInstance _i1(_cimName);
        CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules")));
        CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2)));
        CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
        CIMProperty _p4(CIMName("TimeOfLastStateChange"),
                        CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

        _i1.addProperty(_p1);
        _i1.addProperty(_p2);
        _i1.addProperty(_p3);
        _i1.addProperty(_p4);

        CQLChainedIdentifier ci1(
            String("CIM_OperatingSystem.CIM_OperatingSystem::Description"));
        CQLChainedIdentifier
        ci2(String("CIM_OperatingSystem.CIM_OperatingSystem::EnabledState"));
        CQLChainedIdentifier ci3(
            String("CIM_OperatingSystem.CIM_OperatingSystem::CurrentTimeZone"));
        CQLChainedIdentifier ci4(
            String("CIM_OperatingSystem.CIM_OperatingSystem::TimeOfLastStateChange"));

        CQLChainedIdentifier
        ci5(String(
                "CIM_OperatingSystem.CIM_EnabledLogicalElement::TimeOfLastStateChange"));

        CQLChainedIdentifier
        ci7(String("CIM_OperatingSystem"));

        CQLChainedIdentifier
        ci9(String(
                "CIM_EnabledLogicalElement.CIM_OperatingSystem::CSCreationClassName"));

        CQLChainedIdentifier
        ci10(String("CIM_OperatingSystem.CIM_OperatingSystem::Bubba"));

        CQLValue a1(ci1);
        CQLValue a2(ci2);
        CQLValue a3(ci3);
        CQLValue a4(ci4);
        CQLValue a5(ci5);

        CQLValue a7(ci7);

        CQLValue a9(ci9);
        CQLValue a10(ci10);

        CQLValue a11(_query.getClass(CIMName("CIM_OperatingSystem")));

        a1.resolve(_i1, _query);
        a2.resolve(_i1, _query);
        a3.resolve(_i1, _query);
        a4.resolve(_i1, _query);
        a5.resolve(_i1, _query);
        a7.resolve(_i1, _query);
        a10.resolve(_i1, _query1);

        a9.resolve(_i1, _query);

        PEGASUS_TEST_ASSERT(a1 == CQLValue(String("Dave Rules")));
        PEGASUS_TEST_ASSERT(a2 == CQLValue(Uint64(2)));
        PEGASUS_TEST_ASSERT(a3 == CQLValue(Sint64(-600)));
        PEGASUS_TEST_ASSERT(a4 == CQLValue(
                                CIMDateTime(String("20040811105625.000000-360"))));
        PEGASUS_TEST_ASSERT(a5 == CQLValue(
                                CIMDateTime(String("20040811105625.000000-360"))));
        //PEGASUS_TEST_ASSERT(a7 == CQLValue(_i1));
        PEGASUS_TEST_ASSERT(a9.isNull());
        PEGASUS_TEST_ASSERT(a10.isNull());

    }
    catch(Exception & e)
    {
        cout << e.getMessage() << endl;
        PEGASUS_TEST_ASSERT(0);
    }
    delete _rep;
    return;
}