Skip to content

Commit

Permalink
Added tests of FlowTemplate insertion into model.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcphillips committed Nov 4, 2017
1 parent d063f02 commit f12cabe
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/yw-extract/annotation_accessors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,12 @@ namespace yw {
return std::tuple<std::string, std::string>{ pathTemplateText, pathTemplate->getText() };
}

std::tuple<std::string, std::string, std::string> safelyGetComponentsFromUriResourceContext(YWParser::UriContext *uri) {
std::tuple<nullable_string, std::string, std::string> safelyGetComponentsFromUriResourceContext(YWParser::UriContext *uri) {

YWParser::PathTemplateContext* pathTemplate;
YWParser::UriTemplateContext* uriTemplate;
YWParser::SchemeContext* scheme;
std::string schemeText;
nullable_string schemeText;
std::string pathTemplateText;
std::string uriTemplateText;

Expand All @@ -315,13 +315,9 @@ namespace yw {
schemeText = scheme->getText();
}

return std::tuple<std::string, std::string, std::string> { schemeText, pathTemplateText, uriTemplateText };
return std::tuple<nullable_string, std::string, std::string> { schemeText, pathTemplateText, uriTemplateText };
}

//flowTemplateScheme = context->uri()->uriTemplate()->scheme()->getText();
//flowTemplatePath = context->uri()->uriTemplate()->pathTemplate()->getText();


std::string safelyGetAliasNameFromAliasContext(YWParser::AliasContext *alias) {

YWParser::DataNameContext* dataName;
Expand Down
2 changes: 1 addition & 1 deletion src/yw-extract/annotation_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace yw {
std::string safelyGetPortNameFromPortNameContext(YWParser::PortNameContext *portName);
std::string safelyGetAliasNameFromAliasContext(YWParser::AliasContext *alias);
std::tuple<std::string, std::string> safelyGetComponentsFromFileResourceContext(YWParser::FileContext *file);
std::tuple<std::string, std::string, std::string> safelyGetComponentsFromUriResourceContext(YWParser::UriContext *uri);
std::tuple<nullable_string, std::string, std::string> safelyGetComponentsFromUriResourceContext(YWParser::UriContext *uri);

yw::db::Annotation::Tag safelyGetPortTagFromPortContext(YWParser::PortContext *port);
yw::db::Flow::Direction safelyGetPortDirection(YWParser::PortContext *port);
Expand Down
2 changes: 2 additions & 0 deletions test/yw-db-tests/yw_db_test_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ inline SimpleString StringFrom(const yw::db::DataBlock& row) { return StringFrom
inline SimpleString StringFrom(const yw::db::Extraction& row) { return StringFrom(row.str()); }
inline SimpleString StringFrom(const yw::db::File& row) { return StringFrom(row.str()); }
inline SimpleString StringFrom(const yw::db::Flow& row) { return StringFrom(row.str()); }
inline SimpleString StringFrom(const yw::db::FlowTemplate& row) { return StringFrom(row.str()); }
inline SimpleString StringFrom(const yw::db::Line& row) { return StringFrom(row.str()); }
inline SimpleString StringFrom(const yw::db::Port& row) { return StringFrom(row.str()); }
inline SimpleString StringFrom(const yw::db::ProgramBlock& row) { return StringFrom(row.str()); }
Expand All @@ -29,6 +30,7 @@ namespace Microsoft {
static std::wstring ToString(const yw::db::Extraction& row) { RETURN_WIDE_STRING(row); }
static std::wstring ToString(const yw::db::File& row) { RETURN_WIDE_STRING(row); }
static std::wstring ToString(const yw::db::Flow& row) { RETURN_WIDE_STRING(row); }
static std::wstring ToString(const yw::db::FlowTemplate& row) { RETURN_WIDE_STRING(row); }
static std::wstring ToString(const yw::db::Line& row) { RETURN_WIDE_STRING(row); }
static std::wstring ToString(const yw::db::Port& row) { RETURN_WIDE_STRING(row); }
static std::wstring ToString(const yw::db::ProgramBlock& row) { RETURN_WIDE_STRING(row); }
Expand Down
109 changes: 109 additions & 0 deletions test/yw-model-tests/model_entity_listener_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,113 @@ YW_TEST_SET
Assert::AreEqual(dataBlock1.id, flow4.dataBlockId);
}

YW_TEST(ModelEntityListener, WhenOutPortHasFileAnnotationWithSimpleFileNameArgumentFlowTemplateAnnotationContainsFileNameAsPath)
{
this->storeAndParse(R"(
@begin b
@out d @file foo.txt
@end b
@begin c
@in d
@end c
)");
Expect::EmptyString(stderrRecorder.str());

Expect::AreEqual(2, ywdb.getRowCount("flow"));
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));

auto flow = ywdb.selectFlowById(1);
auto flowTemplate = ywdb.selectFlowTemplateById(1);

Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
Expect::AreEqual(FlowTemplate{ 1, 1, null_string, "foo.txt" }, flowTemplate);

Assert::AreEqual(flow.id, flowTemplate.flow);
}

YW_TEST(ModelEntityListener, WhenOutPortHasUriAnnotationWithSimpleFileNameArgumentFlowTemplateAnnotationContainsFileNameAsPath)
{
this->storeAndParse(R"(
@begin b
@out d @uri foo.txt
@end b
@begin c
@in d
@end c
)");
Expect::EmptyString(stderrRecorder.str());

Expect::AreEqual(2, ywdb.getRowCount("flow"));
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));

auto flow = ywdb.selectFlowById(1);
auto flowTemplate = ywdb.selectFlowTemplateById(1);

Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
Expect::AreEqual(FlowTemplate{ 1, 1, null_string, "foo.txt" }, flowTemplate);

Assert::AreEqual(flow.id, flowTemplate.flow);
}

YW_TEST(ModelEntityListener, WhenOutPortHasUriAnnotationWithSchemAndSimpleFileNameArgumentFlowTemplateAnnotationContainsSchemeAndFileNameAsPath)
{
this->storeAndParse(R"(
@begin b
@out d @uri file:foo.txt
@end b
@begin c
@in d
@end c
)");
Expect::EmptyString(stderrRecorder.str());

Expect::AreEqual(2, ywdb.getRowCount("flow"));
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));

auto flow = ywdb.selectFlowById(1);
auto flowTemplate = ywdb.selectFlowTemplateById(1);

Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
Expect::AreEqual(FlowTemplate{ 1, 1, "file", "foo.txt" }, flowTemplate);

Assert::AreEqual(flow.id, flowTemplate.flow);
}

YW_TEST(ModelEntityListener, WhenOutPortHasUriAnnotationWithGeneralUrlArgumentFlowTemplateAnnotationContainsSchemeAndPath)
{
this->storeAndParse(R"(
@begin b
@out d @uri http://foo.org/a.dir/general.dir/url/bar.txt
@end b
@begin c
@in d
@end c
)");
Expect::EmptyString(stderrRecorder.str());

Expect::AreEqual(2, ywdb.getRowCount("flow"));
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));

auto flow = ywdb.selectFlowById(1);
auto flowTemplate = ywdb.selectFlowTemplateById(1);

Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
Expect::AreEqual(FlowTemplate{ 1, 1, "http", "//foo.org/a.dir/general.dir/url/bar.txt" }, flowTemplate);

Assert::AreEqual(flow.id, flowTemplate.flow);
}


YW_TEST_END

0 comments on commit f12cabe

Please sign in to comment.