Merge pull request #2 from 30x/xapid520-521-530

Xapid520 521 530
diff --git a/api_test.go b/api_test.go
index 7a0b86a..74ecf36 100644
--- a/api_test.go
+++ b/api_test.go
@@ -20,228 +20,52 @@
 			db := getDB()
 			txn, err := db.Begin()
 			Expect(err).ShouldNot(HaveOccurred())
-
+			// api products
 			for i := 0; i < 10; i++ {
-				var rows []common.Row
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "api_product_" + result,
-					Type:  1,
-				}
-				srvItems["id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "{/**, /test}",
-					Type:  1,
-				}
-				srvItems["api_resources"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "{Env_0, Env_1}",
-					Type:  1,
-				}
-				srvItems["environments"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  1,
-				}
-				srvItems["_change_selector"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "tenant_id_xxxx",
-					Type:  1,
-				}
-				srvItems["tenant_id"] = scv
-				rows = append(rows, srvItems)
-				res := insertAPIproducts(rows, txn)
+				row := generateTestApiProduct(i)
+				res := insertAPIproducts([]common.Row{row}, txn)
+				Expect(res).Should(BeTrue())
+			}
+			// developers
+			for i := 0; i < 10; i++ {
+				row := generateTestDeveloper(i)
+				res := insertDevelopers([]common.Row{row}, txn)
+				Expect(res).Should(BeTrue())
+			}
+			// companies
+			for i := 0; i < 10; i++ {
+				row := generateTestCompany(i)
+				res := insertCompanies([]common.Row{row}, txn)
 				Expect(res).Should(BeTrue())
 			}
 
+			// company developers
 			for i := 0; i < 10; i++ {
-				var rows []common.Row
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "developer_id_" + result,
-					Type:  1,
-				}
-				srvItems["id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "test@apigee.com",
-					Type:  1,
-				}
-				srvItems["email"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Active",
-					Type:  1,
-				}
-				srvItems["status"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Apigee",
-					Type:  1,
-				}
-				srvItems["firstName"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Google",
-					Type:  1,
-				}
-				srvItems["lastName"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  1,
-				}
-				srvItems["_change_selector"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "tenant_id_xxxx",
-					Type:  1,
-				}
-				srvItems["tenant_id"] = scv
-
-				rows = append(rows, srvItems)
-				res := insertDevelopers(rows, txn)
+				row := generateTestCompanyDeveloper(i);
+				res := insertCompanyDevelopers([]common.Row{row}, txn)
 				Expect(res).Should(BeTrue())
 			}
 
+			// application
 			var j, k int
 			for i := 0; i < 10; i++ {
-				resulti := strconv.FormatInt(int64(i), 10)
 				for j = k; j < 10+k; j++ {
-					var rows []common.Row
-
-					srvItems := common.Row{}
-					resultj := strconv.FormatInt(int64(j), 10)
-
-					scv := &common.ColumnVal{
-						Value: "application_id_" + resultj,
-						Type:  1,
-					}
-					srvItems["id"] = scv
-
-					scv = &common.ColumnVal{
-						Value: "developer_id_" + resulti,
-						Type:  1,
-					}
-					srvItems["developer_id"] = scv
-
-					scv = &common.ColumnVal{
-						Value: "approved",
-						Type:  1,
-					}
-					srvItems["status"] = scv
-
-					scv = &common.ColumnVal{
-						Value: "http://apigee.com",
-						Type:  1,
-					}
-					srvItems["callback_url"] = scv
-
-					scv = &common.ColumnVal{
-						Value: "Org_0",
-						Type:  1,
-					}
-					srvItems["_change_selector"] = scv
-
-					scv = &common.ColumnVal{
-						Value: "tenant_id_xxxx",
-						Type:  1,
-					}
-					srvItems["tenant_id"] = scv
-					rows = append(rows, srvItems)
-					res := insertApplications(rows, txn)
+					row := generateTestApp(j, i);
+					res := insertApplications([]common.Row{row}, txn)
 					Expect(res).Should(BeTrue())
 				}
 				k = j
 			}
-
+			// app credentials
 			for i := 0; i < 10; i++ {
-				var rows []common.Row
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "app_credential_" + result,
-					Type:  1,
-				}
-				srvItems["id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "application_id_" + result,
-					Type:  1,
-				}
-				srvItems["app_id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "approved",
-					Type:  1,
-				}
-				srvItems["status"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  1,
-				}
-				srvItems["_change_selector"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "tenant_id_xxxx",
-					Type:  1,
-				}
-				srvItems["tenant_id"] = scv
-				rows = append(rows, srvItems)
-				res := insertCredentials(rows, txn)
+				row := generateTestAppCreds(i)
+				res := insertCredentials([]common.Row{row}, txn)
 				Expect(res).Should(BeTrue())
 			}
-
+			// api product mapper
 			for i := 0; i < 10; i++ {
-				var rows []common.Row
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "api_product_" + result,
-					Type:  1,
-				}
-				srvItems["apiprdt_id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "application_id_" + result,
-					Type:  1,
-				}
-				srvItems["app_id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "app_credential_" + result,
-					Type:  1,
-				}
-				srvItems["appcred_id"] = scv
-				scv = &common.ColumnVal{
-					Value: "approved",
-					Type:  1,
-				}
-				srvItems["status"] = scv
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  1,
-				}
-				srvItems["_change_selector"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "tenant_id_xxxx",
-					Type:  1,
-				}
-				srvItems["tenant_id"] = scv
-				rows = append(rows, srvItems)
-				res := insertAPIProductMappers(rows, txn)
+				row := generateTestApiProductMapper(i)
+				res := insertAPIProductMappers([]common.Row{row}, txn)
 				Expect(res).Should(BeTrue())
 			}
 
@@ -294,119 +118,35 @@
 			Expect(err).ShouldNot(HaveOccurred())
 
 			for i := 0; i < 10; i++ {
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "api_product_" + result,
-					Type:  3,
-				}
-				srvItems["apiprdt_id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "application_id_" + result,
-					Type:  3,
-				}
-				srvItems["app_id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "app_credential_" + result,
-					Type:  3,
-				}
-				srvItems["appcred_id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  3,
-				}
-				srvItems["_change_selector"] = scv
-
-				res := deleteAPIproductMapper(srvItems, txn)
+				row := generateTestApiProductMapper(i);
+				res := deleteAPIproductMapper(row, txn)
 				Expect(res).Should(BeTrue())
 			}
 
 			for i := 0; i < 10; i++ {
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "app_credential_" + result,
-					Type:  3,
-				}
-				srvItems["id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  3,
-				}
-				srvItems["_change_selector"] = scv
-
-				res := deleteObject("APP_CREDENTIAL", srvItems, txn)
+				row := generateTestAppCreds(i)
+				res := deleteObject("APP_CREDENTIAL", row, txn)
 				Expect(res).Should(BeTrue())
 			}
 			for i := 0; i < 100; i++ {
-
-				srvItems := common.Row{}
-				resultj := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "application_id_" + resultj,
-					Type:  1,
-				}
-				srvItems["id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  1,
-				}
-				srvItems["_change_selector"] = scv
-
-				res := deleteObject("APP", srvItems, txn)
+				row := generateTestApp(i, 999) //TODO we use j in above insertions
+				res := deleteObject("APP", row, txn)
 				Expect(res).Should(BeTrue())
 			}
 
 			for i := 0; i < 10; i++ {
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "developer_id_" + result,
-					Type:  1,
-				}
-				srvItems["id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  1,
-				}
-				srvItems["_change_selector"] = scv
-
-				res := deleteObject("DEVELOPER", srvItems, txn)
+				row := generateTestDeveloper(i)
+				res := deleteObject("DEVELOPER", row, txn)
 				Expect(res).Should(BeTrue())
 			}
 
 			for i := 0; i < 10; i++ {
-				srvItems := common.Row{}
-				result := strconv.FormatInt(int64(i), 10)
-
-				scv := &common.ColumnVal{
-					Value: "api_product_" + result,
-					Type:  1,
-				}
-				srvItems["id"] = scv
-
-				scv = &common.ColumnVal{
-					Value: "Org_0",
-					Type:  1,
-				}
-				srvItems["_change_selector"] = scv
-
-				res := deleteObject("API_PRODUCT", srvItems, txn)
+				row := generateTestApiProduct(i)
+				res := deleteObject("API_PRODUCT", row, txn)
 				Expect(res).Should(BeTrue())
 			}
 
 			txn.Commit()
-
 		})
 
 		It("Negative cases for DB Deletes on KMS tables", func() {
@@ -414,101 +154,57 @@
 			txn, err := db.Begin()
 			Expect(err).ShouldNot(HaveOccurred())
 
-			srvItems := common.Row{}
-			result := "DEADBEEF"
+			row := generateTestApiProductMapper(999)
 
-			scv := &common.ColumnVal{
-				Value: "api_product_" + result,
-				Type:  3,
-			}
-			srvItems["apiprdt_id"] = scv
-
-			scv = &common.ColumnVal{
-				Value: "application_id_" + result,
-				Type:  3,
-			}
-			srvItems["app_id"] = scv
-
-			scv = &common.ColumnVal{
-				Value: "app_credential_" + result,
-				Type:  3,
-			}
-			srvItems["appcred_id"] = scv
-
-			scv = &common.ColumnVal{
-				Value: "Org_0",
-				Type:  3,
-			}
-			srvItems["_change_selector"] = scv
-
-			res := deleteAPIproductMapper(srvItems, txn)
+			res := deleteAPIproductMapper(row, txn)
 			Expect(res).Should(BeFalse())
 
-			res = deleteObject("API_PRODUCT", srvItems, txn)
+			res = deleteObject("API_PRODUCT", row, txn)
 			Expect(res).Should(BeFalse())
 
-			res = deleteObject("APP_CREDENTIAL", srvItems, txn)
+			res = deleteObject("APP_CREDENTIAL", row, txn)
 			Expect(res).Should(BeFalse())
 
-			res = deleteObject("DEVELOPER", srvItems, txn)
+			res = deleteObject("DEVELOPER", row, txn)
 			Expect(res).Should(BeFalse())
 
-			res = deleteObject("APP", srvItems, txn)
+			res = deleteObject("APP", row, txn)
+			Expect(res).Should(BeFalse())
+
+			res = deleteObject("COMPANY", row, txn)
+			Expect(res).Should(BeFalse())
+
+			res = deleteObject("COMPANY_DEVELOPER", row, txn)
 			Expect(res).Should(BeFalse())
 
 			txn.Rollback()
 
 		})
+
 		It("Negative cases for DB Inserts/updates on KMS tables", func() {
 
 			db := getDB()
 			txn, err := db.Begin()
 			Expect(err).ShouldNot(HaveOccurred())
 
-			var rows []common.Row
-			srvItems := common.Row{}
-			result := "NOPRODID_BADCASE"
-			scv := &common.ColumnVal{
-				Value: "foobar_" + result,
-				Type:  1,
-			}
-			srvItems[result] = scv
-
-			scv = &common.ColumnVal{
-				Value: "{/**, /test}",
-				Type:  1,
-			}
-			srvItems["api_resources"] = scv
-
-			scv = &common.ColumnVal{
-				Value: "{Env_1, Env_0}",
-				Type:  1,
-			}
-			srvItems["environments"] = scv
-
-			scv = &common.ColumnVal{
-				Value: "Org_0",
-				Type:  1,
-			}
-			srvItems["_change_selector"] = scv
-
-			scv = &common.ColumnVal{
-				Value: "tenant_id_xxxx",
-				Type:  1,
-			}
-			srvItems["tenant_id"] = scv
-
-			rows = append(rows, srvItems)
-			res := insertAPIproducts(rows, txn)
+			row := generateTestApiProduct(999)
+			row["id"] = nil
+			res := insertAPIproducts([]common.Row{row}, txn)
 			Expect(res).Should(BeFalse())
 
-			res = insertApplications(rows, txn)
+			res = insertApplications([]common.Row{row}, txn)
 			Expect(res).Should(BeFalse())
 
-			res = insertCredentials(rows, txn)
+			res = insertCredentials([]common.Row{row}, txn)
 			Expect(res).Should(BeFalse())
 
-			res = insertAPIProductMappers(rows, txn)
+			res = insertAPIProductMappers([]common.Row{row}, txn)
+			Expect(res).Should(BeFalse())
+
+			res = insertCompanies([]common.Row{row}, txn)
+			Expect(res).Should(BeFalse())
+
+			res = insertCompanyDevelopers([]common.Row{row}, txn)
 			Expect(res).Should(BeFalse())
 
 		})
diff --git a/listener.go b/listener.go
index de80a9b..7dcd4b6 100644
--- a/listener.go
+++ b/listener.go
@@ -248,6 +248,108 @@
 }
 
 /*
+ * Performs Bulk insert of Company Developers
+ */
+func insertCompanyDevelopers(rows []common.Row, txn *sql.Tx) bool {
+	var scope, CompanyId, DeveloperId, tenantId, CreatedBy, LastModifiedBy string
+	var CreatedAt, LastModifiedAt int64
+
+	prep, err := txn.Prepare("INSERT INTO COMPANY_DEVELOPER (_change_selector,company_id,tenant_id,developer_id,created_at,created_by,updated_at,updated_by) VALUES($1,$2,$3,$4,$5,$6,$7,$8);")
+	if err != nil {
+		log.Error("INSERT COMPANY_DEVELOPER Failed: ", err)
+		return false
+	}
+	defer prep.Close()
+	for _, ele := range rows {
+
+		ele.Get("_change_selector", &scope)
+		ele.Get("company_id", &CompanyId)
+		ele.Get("tenant_id", &tenantId)
+		ele.Get("developer_id", &DeveloperId)
+		ele.Get("created_at", &CreatedAt)
+		ele.Get("created_by", &CreatedBy)
+		ele.Get("updated_at", &LastModifiedAt)
+		ele.Get("updated_by", &LastModifiedBy)
+
+		/* Mandatory params check */
+		if scope == "" || tenantId == "" || CompanyId == "" || DeveloperId == ""{
+			log.Error("INSERT COMPANY_DEVELOPER: i/p args missing")
+			return false
+		}
+		_, err = txn.Stmt(prep).Exec(
+			scope,
+			CompanyId,
+			tenantId,
+			DeveloperId,
+			CreatedAt,
+			CreatedBy,
+			LastModifiedAt,
+			LastModifiedBy)
+
+		if err != nil {
+			log.Error("INSERT COMPANY_DEVELOPER Failed: (", DeveloperId, ", ", CompanyId, ", ", scope, ")", err)
+			return false
+		} else {
+			log.Debug("INSERT COMPANY_DEVELOPER Success: (", DeveloperId, ", ", CompanyId, ", ", scope, ")")
+		}
+	}
+	return true
+}
+
+/*
+ * Performs Bulk insert of Companies
+ */
+func insertCompanies(rows []common.Row, txn *sql.Tx) bool {
+	var scope, EntityIdentifier, Name, DisplayName, Status, tenantId, CreatedBy, LastModifiedBy string
+	var CreatedAt, LastModifiedAt int64
+
+	prep, err := txn.Prepare("INSERT INTO COMPANY (_change_selector,id,tenant_id,status,name,display_name,created_at,created_by,updated_at,updated_by) VALUES($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);")
+	if err != nil {
+		log.Error("INSERT COMPANY Failed: ", err)
+		return false
+	}
+	defer prep.Close()
+	for _, ele := range rows {
+
+		ele.Get("_change_selector", &scope)
+		ele.Get("id", &EntityIdentifier)
+		ele.Get("tenant_id", &tenantId)
+		ele.Get("status", &Status)
+		ele.Get("name", &Name)
+		ele.Get("display_name", &DisplayName)
+		ele.Get("created_at", &CreatedAt)
+		ele.Get("created_by", &CreatedBy)
+		ele.Get("updated_at", &LastModifiedAt)
+		ele.Get("updated_by", &LastModifiedBy)
+
+		/* Mandatory params check */
+		if EntityIdentifier == "" || scope == "" || tenantId == "" {
+			log.Error("INSERT COMPANY: i/p args missing")
+			return false
+		}
+		_, err = txn.Stmt(prep).Exec(
+			scope,
+			EntityIdentifier,
+			tenantId,
+			Status,
+			Name,
+			DisplayName,
+			CreatedAt,
+			CreatedBy,
+			LastModifiedAt,
+			LastModifiedBy)
+
+		if err != nil {
+			log.Error("INSERT COMPANY Failed: (", EntityIdentifier, ", ", scope, ")", err)
+			return false
+		} else {
+			log.Debug("INSERT COMPANY Success: (", EntityIdentifier, ", ", scope, ")")
+		}
+	}
+	return true
+}
+
+/*
  * Performs Bulk insert of API products
  */
 func insertAPIproducts(rows []common.Row, txn *sql.Tx) bool {
@@ -404,7 +506,34 @@
 			case common.Delete:
 				ok = deleteObject("APP", payload.OldRow, txn)
 			}
+		case "kms.company":
+			switch payload.Operation {
+			case common.Insert:
+				rows = append(rows, payload.NewRow)
+				ok = insertCompanies(rows, txn)
 
+			case common.Update:
+				ok = deleteObject("COMPANY", payload.OldRow, txn)
+				rows = append(rows, payload.NewRow)
+				ok = insertCompanies(rows, txn)
+
+			case common.Delete:
+				ok = deleteObject("COMPANY", payload.OldRow, txn)
+			}
+		case "kms.company_developer":
+			switch payload.Operation {
+			case common.Insert:
+				rows = append(rows, payload.NewRow)
+				ok = insertCompanyDevelopers(rows, txn)
+
+			case common.Update:
+				ok = deleteObject("COMPANY_DEVELOPER", payload.OldRow, txn)
+				rows = append(rows, payload.NewRow)
+				ok = insertCompanyDevelopers(rows, txn)
+
+			case common.Delete:
+				ok = deleteObject("COMPANY_DEVELOPER", payload.OldRow, txn)
+			}
 		case "kms.app_credential":
 			switch payload.Operation {
 			case common.Insert:
diff --git a/listener_test.go b/listener_test.go
index 8305836..7c7860c 100644
--- a/listener_test.go
+++ b/listener_test.go
@@ -20,7 +20,7 @@
 				"id": {
 					Value: "ch_api_product_2",
 				},
-				"apid_resources": {
+				"api_resources": {
 					Value: "{}",
 				},
 				"environments": {
@@ -50,6 +50,45 @@
 				},
 			}
 
+			companyItems := common.Row{
+				"id": {
+					Value: "ch_company_id_2",
+				},
+				"status": {
+					Value: "Active",
+				},
+				"tenant_id": {
+					Value: "tenant_id_0",
+				},
+				"_change_selector": {
+					Value: "test_org0",
+				},
+				"name": {
+					Value: "test_company_name0",
+				},
+				"display_name": {
+					Value: "test_company_display_name0",
+				},
+			}
+
+			companyDeveloperItems := common.Row{
+				"id": {
+					Value: "ch_developer_id_2",
+				},
+				"tenant_id": {
+					Value: "tenant_id_0",
+				},
+				"_change_selector": {
+					Value: "test_org0",
+				},
+				"company_id": {
+					Value: "ch_company_id_2",
+				},
+				"developer_id": {
+					Value: "ch_developer_id_2",
+				},
+			}
+
 			/* APP */
 			appItems := common.Row{
 				"id": {
@@ -136,6 +175,16 @@
 					NewRow:    mpItems,
 					Operation: 1,
 				},
+				{
+					Table:     "kms.company",
+					NewRow:    companyItems,
+					Operation: 1,
+				},
+				{
+					Table:     "kms.company_developer",
+					NewRow:    companyDeveloperItems,
+					Operation: 1,
+				},
 			}
 
 			h := &test_handler{
@@ -182,7 +231,7 @@
 			"id": {
 				Value: "ch_api_product_0",
 			},
-			"apid_resources": {
+			"api_resources": {
 				Value: "{}",
 			},
 			"environments": {
@@ -231,6 +280,45 @@
 			},
 		}
 
+		companyItemsOld := common.Row{
+			"id": {
+				Value: "ch_company_id_0",
+			},
+			"status": {
+				Value: "Active",
+			},
+			"tenant_id": {
+				Value: "tenant_id_0",
+			},
+			"_change_selector": {
+				Value: "test_org0",
+			},
+			"name": {
+				Value: "test_company_name0",
+			},
+			"display_name": {
+				Value: "test_company_display_name0",
+			},
+		}
+
+		companyDeveloperItemsOld := common.Row{
+			"id": {
+				Value: "ch_developer_id_0",
+			},
+			"tenant_id": {
+				Value: "tenant_id_0",
+			},
+			"_change_selector": {
+				Value: "test_org0",
+			},
+			"company_id": {
+				Value: "ch_company_id_0",
+			},
+			"developer_id": {
+				Value: "ch_developer_id_0",
+			},
+		}
+
 		/* CRED */
 		credItemsOld := common.Row{
 			"id": {
@@ -278,7 +366,7 @@
 			"id": {
 				Value: "ch_api_product_1",
 			},
-			"apid_resources": {
+			"api_resources": {
 				Value: "{}",
 			},
 			"environments": {
@@ -308,6 +396,45 @@
 			},
 		}
 
+		companyItemsNew := common.Row{
+			"id": {
+				Value: "ch_company_id_1",
+			},
+			"status": {
+				Value: "Active",
+			},
+			"tenant_id": {
+				Value: "tenant_id_0",
+			},
+			"_change_selector": {
+				Value: "test_org0",
+			},
+			"name": {
+				Value: "test_company_name0",
+			},
+			"display_name": {
+				Value: "test_company_display_name0",
+			},
+		}
+
+		companyDeveloperItemsNew := common.Row{
+			"id": {
+				Value: "ch_developer_id_1",
+			},
+			"tenant_id": {
+				Value: "tenant_id_0",
+			},
+			"_change_selector": {
+				Value: "test_org0",
+			},
+			"company_id": {
+				Value: "ch_company_id_1",
+			},
+			"developer_id": {
+				Value: "ch_developer_id_1",
+			},
+		}
+
 		/* APP */
 		appItemsNew := common.Row{
 			"id": {
@@ -380,6 +507,16 @@
 				Operation: 1,
 			},
 			{
+				Table:     "kms.company",
+				NewRow:    companyItemsOld,
+				Operation: 1,
+			},
+			{
+				Table:     "kms.company_developer",
+				NewRow:    companyDeveloperItemsOld,
+				Operation: 1,
+			},
+			{
 				Table:     "kms.app",
 				NewRow:    appItemsOld,
 				Operation: 1,
@@ -410,6 +547,18 @@
 				Operation: 2,
 			},
 			{
+				Table:     "kms.company",
+				OldRow:    companyItemsOld,
+				NewRow:    companyItemsNew,
+				Operation: 2,
+			},
+			{
+				Table:     "kms.company_developer",
+				OldRow:    companyDeveloperItemsOld,
+				NewRow:    companyDeveloperItemsNew,
+				Operation: 2,
+			},
+			{
 				Table:     "kms.app",
 				OldRow:    appItemsOld,
 				NewRow:    appItemsNew,
@@ -461,7 +610,6 @@
 		apid.Events().Emit("ApigeeSync", &event2)
 		apid.Events().Emit("ApigeeSync", &common.ChangeList{})
 	})
-
 })
 
 type test_handler struct {
diff --git a/test_helper.go b/test_helper.go
new file mode 100644
index 0000000..61f8f00
--- /dev/null
+++ b/test_helper.go
@@ -0,0 +1,167 @@
+package apidVerifyApiKey
+
+import (
+	"github.com/apigee-labs/transicator/common"
+	"strconv"
+)
+
+func convertSuffix(i int) string{
+	return strconv.FormatInt(int64(i), 10)
+}
+
+func generateTestApiProduct(suffix int) common.Row{
+	return common.Row{
+		"id": {
+			Value: "api_product_" + convertSuffix(suffix),
+		},
+		"api_resources": {
+			Value: "{/**, /test}",
+		},
+		"environments": {
+			Value: "{Env_0, Env_1}",
+		},
+		"tenant_id": {
+			Value: "tenant_id_xxxx",
+		},
+		"_change_selector": {
+			Value: "Org_0",
+		},
+	}
+}
+
+func generateTestDeveloper(suffix int) common.Row {
+	 return common.Row{
+		"id": {
+			Value: "developer_id_" + convertSuffix(suffix),
+		},
+		"status": {
+			Value: "Active",
+		},
+		"email": {
+			Value: "test@apigee.com",
+		},
+		"first_name": {
+			Value: "Apigee",
+		},
+		"last_name": {
+			Value: "Google",
+		},
+		"tenant_id": {
+			Value: "tenant_id_xxxx",
+		},
+		"_change_selector": {
+			Value: "Org_0",
+		},
+	}
+}
+
+func generateTestCompany(suffix int) common.Row {
+	return common.Row{
+		"id": {
+			Value: "company_id_" + convertSuffix(suffix),
+		},
+		"status": {
+			Value: "Active",
+		},
+		"name": {
+			Value: "Apigee Corporation",
+		},
+		"display_name": {
+			Value: "Apigee",
+		},
+		"tenant_id": {
+			Value: "tenant_id_xxxx",
+		},
+		"_change_selector": {
+			Value: "Org_0",
+		},
+	}
+}
+
+func generateTestCompanyDeveloper(suffix int) common.Row {
+	return common.Row{
+		"developer_id": {
+			Value: "developer_id_" + convertSuffix(suffix),
+		},
+		"tenant_id": {
+			Value: "tenant_id_0",
+		},
+		"_change_selector": {
+			Value: "test_org0",
+		},
+		"company_id": {
+			Value: "company_id_" + convertSuffix(suffix),
+		},
+	}
+}
+
+func generateTestApp(suffix1, suffix2 int) common.Row {
+	return common.Row{
+		"id": {
+			Value: "application_id_" + convertSuffix(suffix1),
+		},
+		"developer_id": {
+			Value: "developer_id_" + convertSuffix(suffix2),
+		},
+		"status": {
+			Value: "Approved",
+		},
+		"tenant_id": {
+			Value: "tenant_id_xxxx",
+		},
+		"callback_url": {
+			Value: "http://apigee.com",
+		},
+		"_change_selector": {
+			Value: "Org_0",
+		},
+	}
+}
+
+func generateTestAppCreds(suffix int) common.Row {
+	return common.Row{
+		"id": {
+			Value: "app_credential_" + convertSuffix(suffix),
+		},
+		"app_id": {
+			Value: "application_id_" + convertSuffix(suffix),
+		},
+		"status": {
+			Value: "Approved",
+		},
+		"tenant_id": {
+			Value: "tenant_id_xxxx",
+		},
+		"callback_url": {
+			Value: "http://apigee.com",
+		},
+		"_change_selector": {
+			Value: "Org_0",
+		},
+	}
+}
+
+func generateTestApiProductMapper(suffix int) common.Row {
+	return common.Row{
+		"apiprdt_id": {
+			Value: "api_product_" + convertSuffix(suffix),
+		},
+		"status": {
+			Value: "Approved",
+		},
+		"app_id": {
+			Value: "application_id_" + convertSuffix(suffix),
+		},
+		"appcred_id": {
+			Value: "app_credential_" + convertSuffix(suffix),
+		},
+		"tenant_id": {
+			Value: "tenant_id_xxxx",
+		},
+		"_change_selector": {
+			Value: "Org_0",
+		},
+	}
+}
+
+