コード例 #1
0
func TestCatalogGroupSystemBMEcat12(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_light_12.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be != nil, got nil")
	}
	if h.NumberOfCatalogGroups != 6 {
		t.Errorf("expected to read %d catalog groups, got %d", 6, h.NumberOfCatalogGroups)
	}
	if h.NumberOfArticles != 3 {
		t.Errorf("expected to read %d articles, got %d", 3, h.NumberOfArticles)
	}
}
コード例 #2
0
ファイル: article_test.go プロジェクト: meplato/bmecat-go
func TestParseBMEcat12Article(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_light_12_with_classification_groups.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if len(h.Articles) != 3 {
		t.Errorf("expected to read %d articles, got %d", 3, h.NumberOfArticles)
	}

	a := h.Articles[0]

	if a.MimeInfo.NormalSource() != "business_hemd.jpg" {
		t.Errorf("expected normal image, got %v", a.MimeInfo.NormalSource())
	}

	if a.MimeInfo.DataSheetSource() != "" {
		t.Errorf("expected empty data sheet, got %v", a.MimeInfo.DataSheetSource())
	}
}
コード例 #3
0
ファイル: parser_test.go プロジェクト: meplato/bmecat-go
func TestStopAfterHeader(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = false

	file, err := os.Open("fixtures/bmecat_light_12_with_classification_groups.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be nil, got %v", h.Header)
	}
	if h.NumberOfClassificationGroups != 0 {
		t.Errorf("expected to read %d classification groups, got %d", 0, h.NumberOfClassificationGroups)
	}
	if h.NumberOfArticles != 0 {
		t.Errorf("expected to read %d articles, got %d", 0, h.NumberOfArticles)
	}
}
コード例 #4
0
ファイル: product_test.go プロジェクト: meplato/bmecat-go
func TestParseBMEcat2005Product(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_2005.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if len(h.Products) != 3 {
		t.Fatalf("expected to read %d products, got %d", 3, len(h.Products))
	}

	p := h.Products[0]

	if p.MimeInfo.NormalSource() != "business_hemd.jpg" {
		t.Errorf("expected normal image, got %v", p.MimeInfo.NormalSource())
	}

	if p.MimeInfo.DataSheetSource() != "" {
		t.Errorf("expected empty data sheet, got %v", p.MimeInfo.DataSheetSource())
	}
}
コード例 #5
0
ファイル: parser_test.go プロジェクト: meplato/bmecat-go
func TestParseBasicsBMEcat2005(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_2005.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be != nil, got nil")
	}
	/*
		if h.NumberOfClassificationGroups != 6 {
			t.Errorf("expected to read %d classification groups, got %d", 6, h.NumberOfClassificationGroups)
		}
	*/
	if h.NumberOfProducts != 3 {
		t.Errorf("expected to read %d products, got %d", 3, h.NumberOfProducts)
	}
}
コード例 #6
0
func TestArticleSpecialTreatmentClassesBMEcat2005(t *testing.T) {
	h := NewParseArticleSpecialTreatmentHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_2005_with_special_treatment_classes.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be != nil, got nil")
	}
	if h.NumberOfProducts != 3 {
		t.Errorf("expected to read %d products, got %d", 3, h.NumberOfProducts)
	}

	if h.Products[0].SupplierPID.Value != "1245DF" {
		t.Errorf("expected 1st product to be %q, got %q", "1245DF", h.Products[0].SupplierPID.Value)
	}
	if len(h.Products[0].Details.SpecialTreatmentClasses) != 2 {
		t.Errorf("expected 1st product to have %d special treatment classes, got %d", 1, len(h.Products[0].Details.SpecialTreatmentClasses))
	}
	if h.Products[0].Details.SpecialTreatmentClasses[0].Type != "GGVS" {
		t.Errorf("expected 1st product to have special treatment class of type %q, got %q", "GGVS", h.Products[0].Details.SpecialTreatmentClasses[0].Type)
	}
	if h.Products[0].Details.SpecialTreatmentClasses[0].Value != "1201" {
		t.Errorf("expected 1st product to have special treatment class value of %q, got %q", "1201", h.Products[0].Details.SpecialTreatmentClasses[0].Value)
	}
	if h.Products[0].Details.SpecialTreatmentClasses[1].Type != "GGVS" {
		t.Errorf("expected 1st product to have special treatment class of type %q, got %q", "GGVS", h.Products[0].Details.SpecialTreatmentClasses[1].Type)
	}
	if h.Products[0].Details.SpecialTreatmentClasses[1].Value != "9876" {
		t.Errorf("expected 1st product to have special treatment class value of %q, got %q", "9876", h.Products[0].Details.SpecialTreatmentClasses[1].Value)
	}

	if h.Products[1].SupplierPID.Value != "112345vsdfg" {
		t.Errorf("expected 2nd product to be %q, got %q", "112345vsdfg", h.Products[1].SupplierPID.Value)
	}
	if len(h.Products[1].Details.SpecialTreatmentClasses) != 0 {
		t.Errorf("expected 2nd product to have %d special treatment classes, got %d", 0, len(h.Products[1].Details.SpecialTreatmentClasses))
	}

	if h.Products[2].SupplierPID.Value != "74653" {
		t.Errorf("expected 3rd product to be %q, got %q", "74653", h.Products[2].SupplierPID.Value)
	}
	if len(h.Products[2].Details.SpecialTreatmentClasses) != 0 {
		t.Errorf("expected 3rd product to have %d special treatment classes, got %d", 0, len(h.Products[2].Details.SpecialTreatmentClasses))
	}
}
コード例 #7
0
ファイル: features_test.go プロジェクト: meplato/bmecat-go
func TestArticleFeaturesBMEcat2005(t *testing.T) {
	h := NewParseArticleFeaturesHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_2005_with_product_status.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be != nil, got nil")
	}
	if h.NumberOfProducts != 3 {
		t.Errorf("expected to read %d products, got %d", 3, h.NumberOfProducts)
	}

	if h.Products[0].SupplierPID.Value != "1245DF" {
		t.Fatalf("expected 1st article to be %q, got %q", "1245DF", h.Products[0].SupplierPID.Value)
	}
	if len(h.Products[0].Features) != 1 {
		t.Fatalf("expected 1st article to have %d feature, got %d", 1, len(h.Products[0].Features))
	}
	if h.Products[0].Features[0].FeatureSystemName != "ECLASS-5.1" {
		t.Errorf("expected 1st article to have REFERENCE_FEATURE_SYSTEM_NAME = %q, got %q", "ECLASS-5.1", h.Products[0].Features[0].FeatureSystemName)
	}
	if len(h.Products[0].Features[0].FeatureGroupID) != 1 {
		t.Fatalf("expected 1st article to have %d feature group IDs, got %d", 1, len(h.Products[0].Features[0].FeatureGroupID))
	}
	if h.Products[0].Features[0].FeatureGroupID[0].Value != "23-05-91-04" {
		t.Errorf("expected 1st article to have REFERENCE_FEATURE_GROUP_ID = %q, got %q", "23-05-91-04", h.Products[0].Features[0].FeatureGroupID)
	}
	if len(h.Products[0].Features[0].Features) != 5 {
		t.Fatalf("expected 1st article to have %d feature, got %d", 5, len(h.Products[0].Features[0].Features))
	}
	if h.Products[0].Features[0].Features[0].Name != "Kragen" {
		t.Errorf("expected 1st article to have FNAME = %q, got %q", "Kragen", h.Products[0].Features[0].Features[0].Name)
	}
}
コード例 #8
0
ファイル: parser_test.go プロジェクト: meplato/bmecat-go
func TestParseHeader(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_light_12_with_classification_groups.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be != nil, got nil")
	}
	if h.Header.Catalog.Language != "deu" {
		t.Errorf("expected catalog language %s, got %s", "deu", h.Header.Catalog.Language)
	}
	if h.Header.Catalog.ID != "124sd34f" {
		t.Errorf("expected catalog id %s, got %s", "124sd34f", h.Header.Catalog.ID)
	}
	if h.Header.Catalog.Version != "2.1" {
		t.Errorf("expected catalog version %s, got %s", "2.1", h.Header.Catalog.Version)
	}
	catalogName := strings.TrimSpace(h.Header.Catalog.Name)
	if catalogName != "Ein einfacher Katalog Maerz 2001" {
		t.Errorf("expected catalog name %s, got %s", "Ein einfacher Katalog Maerz 2001", catalogName)
	}
	if h.Header.Catalog.Currency != "DEM" {
		t.Errorf("expected catalog currency %s, got %s", "DEM", h.Header.Catalog.Currency)
	}
	if h.Header.Buyer.Name != "KaufWut AG" {
		t.Errorf("expected buyer name %s, got %s", "KaufWut AG", h.Header.Buyer.Name)
	}
	if h.Header.Supplier.Name != "HatAlles GmbH" {
		t.Errorf("expected supplier name %s, got %s", "HatAlles GmbH", h.Header.Supplier.Name)
	}
}
コード例 #9
0
ファイル: article_test.go プロジェクト: meplato/bmecat-go
func TestParseBMEcat12ArticlePriceDetails(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_12_with_article_references.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if len(h.Articles) != 3 {
		t.Fatalf("expected to read %d articles, got %d", 3, h.NumberOfArticles)
	}

	a := h.Articles[0]

	if a.PriceDetails == nil {
		t.Fatal("expected ARTICLE_PRICE_DETAILS")
	}
	if len(a.PriceDetails) != 2 {
		t.Fatalf("expected %2 ARTICLE_PRICE_DETAILS, got %d", 2, len(a.PriceDetails))
	}
	pd := a.PriceDetails[0]
	if len(pd.Prices) != 2 {
		t.Fatalf("expected %2 ARTICLE_PRICE, got %d", 2, len(pd.Prices))
	}
	if pd.Prices[0].Type != bmecat.ArticlePriceTypeNetList {
		t.Errorf("expected %q, got %q", bmecat.ArticlePriceTypeNetList, pd.Prices[0].Type)
	}
	if pd.Prices[0].Amount != 129.0 {
		t.Errorf("expected %v, got %v", 129.0, pd.Prices[0].Amount)
	}
	if pd.Prices[0].Currency != "DEM" {
		t.Errorf("expected %q, got %q", "DEM", pd.Prices[0].Currency)
	}
	if pd.Prices[1].Type != bmecat.ArticlePriceTypeNetList {
		t.Errorf("expected %q, got %q", bmecat.ArticlePriceTypeNetList, pd.Prices[1].Type)
	}
	if pd.Prices[1].Amount != 65.95 {
		t.Errorf("expected %v, got %v", 65.95, pd.Prices[1].Amount)
	}
	if pd.Prices[1].Currency != "EUR" {
		t.Errorf("expected %q, got %q", "EUR", pd.Prices[1].Currency)
	}

	pd = a.PriceDetails[1]
	if len(pd.Prices) != 2 {
		t.Fatalf("expected %2 ARTICLE_PRICE, got %d", 2, len(pd.Prices))
	}
	if pd.Prices[0].Type != bmecat.ArticlePriceTypeNetCustomer {
		t.Errorf("expected %q, got %q", bmecat.ArticlePriceTypeNetCustomer, pd.Prices[0].Type)
	}
	if pd.Prices[0].Amount != 99.0 {
		t.Errorf("expected %v, got %v", 99.0, pd.Prices[0].Amount)
	}
	if pd.Prices[0].Currency != "DEM" {
		t.Errorf("expected %q, got %q", "DEM", pd.Prices[0].Currency)
	}
	if pd.Prices[1].Type != bmecat.ArticlePriceTypeNetCustomer {
		t.Errorf("expected %q, got %q", bmecat.ArticlePriceTypeNetList, pd.Prices[1].Type)
	}
	if pd.Prices[1].Amount != 48.95 {
		t.Errorf("expected %v, got %v", 48.95, pd.Prices[1].Amount)
	}
	if pd.Prices[1].Currency != "EUR" {
		t.Errorf("expected %q, got %q", "EUR", pd.Prices[1].Currency)
	}
}
コード例 #10
0
ファイル: article_test.go プロジェクト: meplato/bmecat-go
func TestParseBMEcat12ArticleFeatures(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_12_with_article_features.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if len(h.Articles) != 3 {
		t.Fatalf("expected to read %d articles, got %d", 3, h.NumberOfArticles)
	}

	a := h.Articles[0]

	if got, want := len(a.Features), 3; got != want {
		t.Fatalf("expected %v features; got: %v", want, got)
	}
	if got, want := a.Features[0].FeatureSystemName, "ECLASS-5.1"; got != want {
		t.Fatalf("expected FeatureSystemName=%v; got: %v", want, got)
	}
	if got, want := a.Features[0].IsEclass(), true; got != want {
		t.Fatalf("expected IsEclass=%v; got: %v", want, got)
	}
	if got, want := a.Features[0].FeatureGroupID, "24-22-06-01"; !reflect.DeepEqual(got, want) {
		t.Fatalf("expected FeatureGroupID=%v; got: %v", want, got)
	}
	if got, want := len(a.Features[0].Features), 0; got != want {
		t.Fatalf("expected %v features; got: %v", want, got)
	}
	if got, want := a.Features[1].FeatureSystemName, "0001"; got != want {
		t.Fatalf("expected FeatureSystemName=%v; got: %v", want, got)
	}
	if got, want := a.Features[1].FeatureGroupID, "0000000007"; !reflect.DeepEqual(got, want) {
		t.Fatalf("expected FeatureGroupID=%v; got: %v", want, got)
	}
	if got, want := len(a.Features[1].Features), 0; got != want {
		t.Fatalf("expected %v features; got: %v", want, got)
	}
	if got, want := a.Features[2].FeatureSystemName, ""; got != want {
		t.Fatalf("expected FeatureSystemName=%v; got: %v", want, got)
	}
	if got, want := len(a.Features[2].FeatureGroupID), 0; got != want {
		t.Fatalf("expected FeatureGroupID=%v; got: %v", want, got)
	}
	if got, want := len(a.Features[2].Features), 2; got != want {
		t.Fatalf("expected %v features; got: %v", want, got)
	}
	if got, want := a.Features[2].Features[0].Name, "Weight"; got != want {
		t.Fatalf("expected feature name %v; got: %v", want, got)
	}
	if got, want := a.Features[2].Features[0].Values, []string{"1"}; !reflect.DeepEqual(got, want) {
		t.Fatalf("expected feature values %v; got: %v", want, got)
	}
	if got, want := a.Features[2].Features[0].Unit, "KGM"; got != want {
		t.Fatalf("expected feature unit %v; got: %v", want, got)
	}
	if got, want := a.Features[2].Features[1].Name, "Importance"; got != want {
		t.Fatalf("expected feature name %v; got: %v", want, got)
	}
	if got, want := a.Features[2].Features[1].Values, []string{"VIP", "Secret"}; !reflect.DeepEqual(got, want) {
		t.Fatalf("expected feature values %v; got: %v", want, got)
	}
	if got, want := a.Features[2].Features[1].Unit, ""; got != want {
		t.Fatalf("expected feature unit %v; got: %v", want, got)
	}
}
コード例 #11
0
ファイル: status_test.go プロジェクト: meplato/bmecat-go
func TestArticleStatusBMEcat2005(t *testing.T) {
	h := NewParseArticleStatusHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_2005_with_product_status.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be != nil, got nil")
	}
	if h.NumberOfProducts != 3 {
		t.Errorf("expected to read %d products, got %d", 3, h.NumberOfProducts)
	}

	if h.Products[0].SupplierPID.Value != "1245DF" {
		t.Fatalf("expected 1st article to be %q, got %q", "1245DF", h.Products[0].SupplierPID.Value)
	}
	if len(h.Products[0].Details.ProductStatus) != 2 {
		t.Fatalf("expected 1st article to have %d states, got %d", 2, len(h.Products[0].Details.ProductStatus))
	}
	if h.Products[0].Details.ProductStatus[0].Type != bmecat.ProductStatusBargain {
		t.Fatalf("expected 1st article to have status of type %q, got %q", bmecat.ProductStatusBargain, h.Products[0].Details.ProductStatus[0].Type)
	}
	if h.Products[0].Details.ProductStatus[0].Value != "Sonderangebot" {
		t.Fatalf("expected 1st article to have status %q, got %q", "Sonderangebot", h.Products[0].Details.ProductStatus[0].Value)
	}
	if h.Products[0].Details.ProductStatus[1].Type != bmecat.ProductStatusNewProduct {
		t.Fatalf("expected 1st article to have status of type %q, got %q", bmecat.ProductStatusNewProduct, h.Products[0].Details.ProductStatus[1].Type)
	}
	if h.Products[0].Details.ProductStatus[1].Value != "Neu im Katalog" {
		t.Fatalf("expected 1st article to have status %q, got %q", "Neu im Katalog", h.Products[0].Details.ProductStatus[1].Value)
	}

	if h.Products[1].SupplierPID.Value != "112345vsdfg" {
		t.Fatalf("expected 2nd article to be %q, got %q", "112345vsdfg", h.Products[1].SupplierPID.Value)
	}
	if len(h.Products[1].Details.ProductStatus) != 1 {
		t.Fatalf("expected 2nd article to have %d states, got %d", 1, len(h.Products[1].Details.ProductStatus))
	}
	if h.Products[1].Details.ProductStatus[0].Type != bmecat.ProductStatusCoreProduct {
		t.Fatalf("expected 2nd article to have status of type %q, got %q", bmecat.ProductStatusCoreProduct, h.Products[0].Details.ProductStatus[0].Type)
	}
	if h.Products[1].Details.ProductStatus[0].Value != "" {
		t.Fatalf("expected 2nd article to have status %q, got %q", "", h.Products[0].Details.ProductStatus[0].Value)
	}

	if h.Products[2].SupplierPID.Value != "74653" {
		t.Fatalf("expected 2nd article to be %q, got %q", "74653", h.Products[2].SupplierPID.Value)
	}
	if len(h.Products[2].Details.ProductStatus) != 0 {
		t.Fatalf("expected 2nd article to have no states, got %d", len(h.Products[2].Details.ProductStatus))
	}
}
コード例 #12
0
ファイル: udx_test.go プロジェクト: meplato/bmecat-go
func TestBMEcat12UDX(t *testing.T) {
	h := NewParseHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_light_12_with_udx.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if len(h.Articles) == 0 {
		t.Fatalf("expected to read at least 1 product, got %d", len(h.Articles))
	}

	a := h.Articles[0]

	if len(a.UserDefinedExtensions.Raw) == 0 {
		t.Fatalf("expected to have raw UDX data; got: %v", string(a.UserDefinedExtensions.Raw))
	}
	fields := a.UserDefinedExtensions.Fields()
	if got, want := len(fields), 8; got != want {
		t.Fatalf("expected to have %v UDX fields; got: %v", want, got)
	}
	value, found := fields.Get("CATBUY_40.CUSTOM_FIELD1")
	if !found {
		t.Fatalf("expected to find UDX field %q; got: %v", "CATBUY_40.CUSTOM_FIELD1", found)
	}
	if got, want := value, "Field content 1"; got != want {
		t.Fatalf("expected to find UDX field %q with value %q; got: %q", "CATBUY_40.CUSTOM_FIELD1", want, got)
	}
	value, found = fields.Get("WALLMEDIEN.SUPPLIER_NAME")
	if !found {
		t.Fatalf("expected to find UDX field %q; got: %v", "WALLMEDIEN.SUPPLIER_NAME", found)
	}
	if got, want := value, "Supplier name"; got != want {
		t.Fatalf("expected to find UDX field %q with value %q; got: %q", "WALLMEDIEN.SUPPLIER_NAME", want, got)
	}
	value, found = fields.Get("NO_SUCH_FIELD")
	if found {
		t.Fatalf("expected to not find UDX field %q; got: %v", "NO_SUCH_FIELD", found)
	}
	if got, want := value, ""; got != want {
		t.Fatalf("expected to return blank value for UDX field %q; got: %q", "NO_SUCH_FIELD", got)
	}

	if a.UserDefinedExtensions.CatbuyCustField1 != "Field content 1" {
		t.Fatalf("expected to have UDX.CATBUY_40.CUSTOM_FIELD1='%s', got '%s'", "Field content 1", a.UserDefinedExtensions.CatbuyCustField1)
	}

	if a.UserDefinedExtensions.CatbuyCustField2 != "Field content 2" {
		t.Fatalf("expected to have UDX.CATBUY_40.CUSTOM_FIELD2='%s', got '%s'", "Field content 2", a.UserDefinedExtensions.CatbuyCustField2)
	}

	if a.UserDefinedExtensions.CatbuyCustField3 != "Field content 3" {
		t.Fatalf("expected to have UDX.CATBUY_40.CUSTOM_FIELD3='%s', got '%s'", "Field content 3", a.UserDefinedExtensions.CatbuyCustField3)
	}

	if a.UserDefinedExtensions.CatbuyCustField4 != "Field content 4" {
		t.Fatalf("expected to have UDX.CATBUY_40.CUSTOM_FIELD4='%s', got '%s'", "Field content 4", a.UserDefinedExtensions.CatbuyCustField4)
	}

	if a.UserDefinedExtensions.CatbuyCustField5 != "Field content 5" {
		t.Fatalf("expected to have UDX.CATBUY_40.CUSTOM_FIELD5='%s', got '%s'", "Field content 5", a.UserDefinedExtensions.CatbuyCustField5)
	}
}
コード例 #13
0
ファイル: references_test.go プロジェクト: meplato/bmecat-go
func TestArticleReferencesBMEcat2005(t *testing.T) {
	h := NewParseArticleReferenceHandler()
	h.ContinueAfterHeaderIsFound = true

	file, err := os.Open("fixtures/bmecat_2005_with_product_references.xml")
	if err != nil {
		t.Fatalf("%v", err)
	}
	defer file.Close()

	parser := bmecat.NewParser()
	err = parser.Parse(file, h)
	if err != nil {
		t.Fatalf("parser failed: %v", err)
	}
	if !h.CompleteReached {
		t.Errorf("expected to signal end via HandleComplete, got false")
	}
	if h.Header == nil {
		t.Errorf("expected header to be != nil, got nil")
	}
	if h.NumberOfProducts != 3 {
		t.Errorf("expected to read %d products, got %d", 3, h.NumberOfProducts)
	}

	if h.Products[0].SupplierPID.Value != "1245DF" {
		t.Errorf("expected 1st article to be %q, got %q", "1245DF", h.Products[0].SupplierPID.Value)
	}
	if len(h.Products[0].References) != 1 {
		t.Errorf("expected 1st article to have %d reference, got %d", 1, len(h.Products[0].References))
	}
	if h.Products[0].References[0].Type != bmecat.ProductReferenceTypeSimilar {
		t.Errorf("expected 1st article to have reference of type %q, got %q", bmecat.ProductReferenceTypeSimilar, h.Products[0].References[0].Type)
	}
	if h.Products[0].References[0].ProdIdTo != "112345vsdfg" {
		t.Errorf("expected 1st article to have reference to %q, got %q", "112345vsdfg", h.Products[0].References[0].ProdIdTo)
	}

	if h.Products[1].SupplierPID.Value != "112345vsdfg" {
		t.Errorf("expected 2nd article to be %q, got %q", "112345vsdfg", h.Products[1].SupplierPID.Value)
	}
	if len(h.Products[1].References) != 1 {
		t.Errorf("expected 2nd article to have %d reference, got %d", 1, len(h.Products[1].References))
	}
	if h.Products[1].References[0].Type != bmecat.ProductReferenceTypeSimilar {
		t.Errorf("expected 2nd article to have reference of type %q, got %q", bmecat.ProductReferenceTypeSimilar, h.Products[1].References[0].Type)
	}
	if h.Products[1].References[0].ProdIdTo != "1245DF" {
		t.Errorf("expected 2nd article to have reference to %q, got %q", "1245DF", h.Products[1].References[0].ProdIdTo)
	}

	if h.Products[2].SupplierPID.Value != "74653" {
		t.Errorf("expected 3rd article to be %q, got %q", "74653", h.Products[2].SupplierPID.Value)
	}
	if len(h.Products[2].References) != 2 {
		t.Errorf("expected 3rd article to have %d reference, got %d", 1, len(h.Products[2].References))
	}
	if h.Products[2].References[0].Type != bmecat.ProductReferenceTypeAccessories {
		t.Errorf("expected 3rd article to have reference of type %q, got %q", bmecat.ProductReferenceTypeAccessories, h.Products[2].References[0].Type)
	}
	if h.Products[2].References[0].ProdIdTo != "1245DF" {
		t.Errorf("expected 3rd article to have reference to %q, got %q", "1245DF", h.Products[2].References[0].ProdIdTo)
	}
	if h.Products[2].References[1].Type != bmecat.ProductReferenceTypeAccessories {
		t.Errorf("expected 3rd article to have reference of type %q, got %q", bmecat.ProductReferenceTypeAccessories, h.Products[2].References[1].Type)
	}
	if h.Products[2].References[1].ProdIdTo != "112345vsdfg" {
		t.Errorf("expected 3rd article to have reference to %q, got %q", "112345vsdfg", h.Products[2].References[1].ProdIdTo)
	}
}