Skip to content

Commit f12cabe

Browse files
committed
Added tests of FlowTemplate insertion into model.
1 parent d063f02 commit f12cabe

File tree

4 files changed

+115
-8
lines changed

4 files changed

+115
-8
lines changed

src/yw-extract/annotation_accessors.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,12 @@ namespace yw {
287287
return std::tuple<std::string, std::string>{ pathTemplateText, pathTemplate->getText() };
288288
}
289289

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

292292
YWParser::PathTemplateContext* pathTemplate;
293293
YWParser::UriTemplateContext* uriTemplate;
294294
YWParser::SchemeContext* scheme;
295-
std::string schemeText;
295+
nullable_string schemeText;
296296
std::string pathTemplateText;
297297
std::string uriTemplateText;
298298

@@ -315,13 +315,9 @@ namespace yw {
315315
schemeText = scheme->getText();
316316
}
317317

318-
return std::tuple<std::string, std::string, std::string> { schemeText, pathTemplateText, uriTemplateText };
318+
return std::tuple<nullable_string, std::string, std::string> { schemeText, pathTemplateText, uriTemplateText };
319319
}
320320

321-
//flowTemplateScheme = context->uri()->uriTemplate()->scheme()->getText();
322-
//flowTemplatePath = context->uri()->uriTemplate()->pathTemplate()->getText();
323-
324-
325321
std::string safelyGetAliasNameFromAliasContext(YWParser::AliasContext *alias) {
326322

327323
YWParser::DataNameContext* dataName;

src/yw-extract/annotation_listener.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ namespace yw {
8282
std::string safelyGetPortNameFromPortNameContext(YWParser::PortNameContext *portName);
8383
std::string safelyGetAliasNameFromAliasContext(YWParser::AliasContext *alias);
8484
std::tuple<std::string, std::string> safelyGetComponentsFromFileResourceContext(YWParser::FileContext *file);
85-
std::tuple<std::string, std::string, std::string> safelyGetComponentsFromUriResourceContext(YWParser::UriContext *uri);
85+
std::tuple<nullable_string, std::string, std::string> safelyGetComponentsFromUriResourceContext(YWParser::UriContext *uri);
8686

8787
yw::db::Annotation::Tag safelyGetPortTagFromPortContext(YWParser::PortContext *port);
8888
yw::db::Flow::Direction safelyGetPortDirection(YWParser::PortContext *port);

test/yw-db-tests/yw_db_test_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ inline SimpleString StringFrom(const yw::db::DataBlock& row) { return StringFrom
1010
inline SimpleString StringFrom(const yw::db::Extraction& row) { return StringFrom(row.str()); }
1111
inline SimpleString StringFrom(const yw::db::File& row) { return StringFrom(row.str()); }
1212
inline SimpleString StringFrom(const yw::db::Flow& row) { return StringFrom(row.str()); }
13+
inline SimpleString StringFrom(const yw::db::FlowTemplate& row) { return StringFrom(row.str()); }
1314
inline SimpleString StringFrom(const yw::db::Line& row) { return StringFrom(row.str()); }
1415
inline SimpleString StringFrom(const yw::db::Port& row) { return StringFrom(row.str()); }
1516
inline SimpleString StringFrom(const yw::db::ProgramBlock& row) { return StringFrom(row.str()); }
@@ -29,6 +30,7 @@ namespace Microsoft {
2930
static std::wstring ToString(const yw::db::Extraction& row) { RETURN_WIDE_STRING(row); }
3031
static std::wstring ToString(const yw::db::File& row) { RETURN_WIDE_STRING(row); }
3132
static std::wstring ToString(const yw::db::Flow& row) { RETURN_WIDE_STRING(row); }
33+
static std::wstring ToString(const yw::db::FlowTemplate& row) { RETURN_WIDE_STRING(row); }
3234
static std::wstring ToString(const yw::db::Line& row) { RETURN_WIDE_STRING(row); }
3335
static std::wstring ToString(const yw::db::Port& row) { RETURN_WIDE_STRING(row); }
3436
static std::wstring ToString(const yw::db::ProgramBlock& row) { RETURN_WIDE_STRING(row); }

test/yw-model-tests/model_entity_listener_tests.cpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,4 +689,113 @@ YW_TEST_SET
689689
Assert::AreEqual(dataBlock1.id, flow4.dataBlockId);
690690
}
691691

692+
YW_TEST(ModelEntityListener, WhenOutPortHasFileAnnotationWithSimpleFileNameArgumentFlowTemplateAnnotationContainsFileNameAsPath)
693+
{
694+
this->storeAndParse(R"(
695+
696+
@begin b
697+
@out d @file foo.txt
698+
@end b
699+
700+
@begin c
701+
@in d
702+
@end c
703+
704+
)");
705+
Expect::EmptyString(stderrRecorder.str());
706+
707+
Expect::AreEqual(2, ywdb.getRowCount("flow"));
708+
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));
709+
710+
auto flow = ywdb.selectFlowById(1);
711+
auto flowTemplate = ywdb.selectFlowTemplateById(1);
712+
713+
Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
714+
Expect::AreEqual(FlowTemplate{ 1, 1, null_string, "foo.txt" }, flowTemplate);
715+
716+
Assert::AreEqual(flow.id, flowTemplate.flow);
717+
}
718+
719+
YW_TEST(ModelEntityListener, WhenOutPortHasUriAnnotationWithSimpleFileNameArgumentFlowTemplateAnnotationContainsFileNameAsPath)
720+
{
721+
this->storeAndParse(R"(
722+
723+
@begin b
724+
@out d @uri foo.txt
725+
@end b
726+
727+
@begin c
728+
@in d
729+
@end c
730+
731+
)");
732+
Expect::EmptyString(stderrRecorder.str());
733+
734+
Expect::AreEqual(2, ywdb.getRowCount("flow"));
735+
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));
736+
737+
auto flow = ywdb.selectFlowById(1);
738+
auto flowTemplate = ywdb.selectFlowTemplateById(1);
739+
740+
Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
741+
Expect::AreEqual(FlowTemplate{ 1, 1, null_string, "foo.txt" }, flowTemplate);
742+
743+
Assert::AreEqual(flow.id, flowTemplate.flow);
744+
}
745+
746+
YW_TEST(ModelEntityListener, WhenOutPortHasUriAnnotationWithSchemAndSimpleFileNameArgumentFlowTemplateAnnotationContainsSchemeAndFileNameAsPath)
747+
{
748+
this->storeAndParse(R"(
749+
750+
@begin b
751+
@out d @uri file:foo.txt
752+
@end b
753+
754+
@begin c
755+
@in d
756+
@end c
757+
758+
)");
759+
Expect::EmptyString(stderrRecorder.str());
760+
761+
Expect::AreEqual(2, ywdb.getRowCount("flow"));
762+
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));
763+
764+
auto flow = ywdb.selectFlowById(1);
765+
auto flowTemplate = ywdb.selectFlowTemplateById(1);
766+
767+
Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
768+
Expect::AreEqual(FlowTemplate{ 1, 1, "file", "foo.txt" }, flowTemplate);
769+
770+
Assert::AreEqual(flow.id, flowTemplate.flow);
771+
}
772+
773+
YW_TEST(ModelEntityListener, WhenOutPortHasUriAnnotationWithGeneralUrlArgumentFlowTemplateAnnotationContainsSchemeAndPath)
774+
{
775+
this->storeAndParse(R"(
776+
777+
@begin b
778+
@out d @uri http://foo.org/a.dir/general.dir/url/bar.txt
779+
@end b
780+
781+
@begin c
782+
@in d
783+
@end c
784+
785+
)");
786+
Expect::EmptyString(stderrRecorder.str());
787+
788+
Expect::AreEqual(2, ywdb.getRowCount("flow"));
789+
Expect::AreEqual(1, ywdb.getRowCount("flow_template"));
790+
791+
auto flow = ywdb.selectFlowById(1);
792+
auto flowTemplate = ywdb.selectFlowTemplateById(1);
793+
794+
Expect::AreEqual(Flow{ 1, 1, 1, Direction::OUT, 1, 1 }, flow);
795+
Expect::AreEqual(FlowTemplate{ 1, 1, "http", "//foo.org/a.dir/general.dir/url/bar.txt" }, flowTemplate);
796+
797+
Assert::AreEqual(flow.id, flowTemplate.flow);
798+
}
799+
800+
692801
YW_TEST_END

0 commit comments

Comments
 (0)