[ISSUE-67901957] add db tests
diff --git a/accessEntity/api.go b/accessEntity/api.go
index 75edd9c..eb4561a 100644
--- a/accessEntity/api.go
+++ b/accessEntity/api.go
@@ -45,10 +45,23 @@
 )
 
 const (
+	TypeDeveloper   = "developer"
+	TypeCompany     = "company"
+	TypeApp         = "app"
+	TypeConsumerKey = "consumerkey"
+)
+
+const (
 	AppTypeDeveloper = "DEVELOPER"
 	AppTypeCompany   = "COMPANY"
 )
 
+const (
+	StatusApproved = "APPROVED"
+	StatusRevoked  = "REVOKED"
+	StatusExpired  = "EXPIRED"
+)
+
 var (
 	Identifiers = map[string]bool{
 		"appid":          true,
@@ -250,8 +263,8 @@
 
 	var details []*CompanyDeveloperDetails
 	for _, dev := range devs {
-		comName, err := a.DbMan.GetComNameByComId(dev.CompanyId)
-		if err != nil {
+		comName, err := a.DbMan.GetComNames(dev.CompanyId, TypeCompany)
+		if err != nil || len(comName) == 0 {
 			log.Errorf("getCompanyDeveloper: %v", err)
 			return nil, newDbError(err)
 		}
@@ -260,7 +273,7 @@
 			log.Errorf("getCompanyDeveloper: %v", err)
 			return nil, newDbError(err)
 		}
-		detail := makeComDevDetails(&dev, comName, email)
+		detail := makeComDevDetails(&dev, comName[0], email)
 		details = append(details, detail)
 	}
 	return &CompanyDevelopersSuccessResponse{
@@ -293,12 +306,12 @@
 	dev := &devs[0]
 
 	attrs := a.DbMan.GetKmsAttributes(dev.TenantId, dev.Id)[dev.Id]
-	comNames, err := a.DbMan.GetComNamesByDevId(dev.Id)
+	comNames, err := a.DbMan.GetComNames(dev.Id, TypeDeveloper)
 	if err != nil {
 		log.Errorf("getDeveloper: %v", err)
 		return nil, newDbError(err)
 	}
-	appNames, err := a.DbMan.GetAppNamesByDevId(dev.Id)
+	appNames, err := a.DbMan.GetAppNames(dev.Id, TypeDeveloper)
 	if err != nil {
 		log.Errorf("getDeveloper: %v", err)
 		return nil, newDbError(err)
@@ -334,7 +347,7 @@
 	com := &coms[0]
 
 	attrs := a.DbMan.GetKmsAttributes(com.TenantId, com.Id)[com.Id]
-	appNames, err := a.DbMan.GetAppNamesByComId(com.Id)
+	appNames, err := a.DbMan.GetAppNames(com.Id, TypeApp)
 	if err != nil {
 		log.Errorf("getCompany: %v", err)
 		return nil, newDbError(err)
@@ -420,7 +433,10 @@
 		}, nil
 	}
 	app := &apps[0]
-	cd := a.getCredDetails(appCred, app.Status)
+	cd, errRes := a.getCredDetails(appCred, app.Status)
+	if errRes != nil {
+		return nil, errRes
+	}
 	devStatus := ""
 	if app.DeveloperId != "" {
 		devStatus, err = a.DbMan.GetStatus(app.DeveloperId, AppTypeDeveloper)
@@ -429,8 +445,7 @@
 			return nil, newDbError(err)
 		}
 	}
-	//TODO: isValidKey
-	cks := makeConsumerKeyStatusDetails(app, cd, devStatus, "")
+	cks := makeConsumerKeyStatusDetails(app, cd, devStatus)
 	//TODO: redirectUris
 	details := makeAppCredentialDetails(appCred, cks, []string{}, attrs)
 	return &AppCredentialSuccessResponse{
@@ -466,7 +481,7 @@
 
 	app = &apps[0]
 	attrs = a.DbMan.GetKmsAttributes(app.TenantId, app.Id)[app.Id]
-	prods, err := a.DbMan.GetApiProductNamesByAppId(app.Id)
+	prods, err := a.DbMan.GetApiProductNames(app.Id, TypeApp)
 	if err != nil {
 		log.Errorf("getApp error getting productNames: %v", err)
 		return nil, newDbError(err)
@@ -483,7 +498,11 @@
 	}
 	var credDetails []*CredentialDetails
 	for _, cred := range creds {
-		credDetails = append(credDetails, a.getCredDetails(&cred, app.Status))
+		detail, errRes := a.getCredDetails(&cred, app.Status)
+		if errRes != nil {
+			return nil, errRes
+		}
+		credDetails = append(credDetails, detail)
 	}
 
 	details, errRes := makeAppDetails(app, parStatus, prods, credDetails, attrs)
@@ -500,7 +519,7 @@
 	}, nil
 }
 
-func makeConsumerKeyStatusDetails(app *common.App, c *CredentialDetails, devStatus, isValidKey string) *ConsumerKeyStatusDetails {
+func makeConsumerKeyStatusDetails(app *common.App, c *CredentialDetails, devStatus string) *ConsumerKeyStatusDetails {
 	return &ConsumerKeyStatusDetails{
 		AppCredential:   c,
 		AppID:           c.AppID,
@@ -509,7 +528,7 @@
 		AppType:         app.Type,
 		DeveloperID:     app.DeveloperId,
 		DeveloperStatus: devStatus,
-		IsValidKey:      isValidKey,
+		IsValidKey:      strings.EqualFold(c.Status, StatusApproved),
 	}
 }
 
@@ -641,10 +660,15 @@
 	}
 }
 
-func (a *ApiManager) getCredDetails(cred *common.AppCredential, appStatus string) *CredentialDetails {
+func (a *ApiManager) getCredDetails(cred *common.AppCredential, appStatus string) (*CredentialDetails, *common.ErrorResponse) {
 
+	refs, err := a.DbMan.GetApiProductNames(cred.Id, TypeConsumerKey)
+	if err != nil {
+		log.Errorf("Error when getting product reference list")
+		return nil, newDbError(err)
+	}
 	return &CredentialDetails{
-		ApiProductReferences: []string{}, //TODO
+		ApiProductReferences: refs,
 		AppID:                cred.AppId,
 		AppStatus:            appStatus,
 		Attributes:           a.DbMan.GetKmsAttributes(cred.TenantId, cred.Id)[cred.Id],
@@ -655,7 +679,7 @@
 		MethodType:           cred.MethodType,
 		Scopes:               common.JsonToStringArray(cred.Scopes),
 		Status:               cred.Status,
-	}
+	}, nil
 }
 
 func parseIdentifiers(endpoint string, ids map[string]string) (valid bool, keyVals []string) {
diff --git a/accessEntity/api_response.go b/accessEntity/api_response.go
index 04bca8d..a743bfb 100644
--- a/accessEntity/api_response.go
+++ b/accessEntity/api_response.go
@@ -1,3 +1,17 @@
+// Copyright 2017 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
 package accessEntity
 
 import "github.com/apid/apidVerifyApiKey/common"
@@ -180,6 +194,14 @@
 	Status string `json:"status,omitempty"`
 }
 
+/*
+type ApiProductReferenceDetails struct {
+	// status of the api product
+	Status         string `json:"status,omitempty"`
+	// name of the api product
+	ApiProduct string `json:"apiProduct,omitempty"`
+}
+*/
 type AppCredentialDetails struct {
 	// app Id
 	AppID string `json:"appId,omitempty"`
@@ -219,7 +241,7 @@
 	// developer status
 	DeveloperStatus string `json:"developerStatus,omitempty"`
 	// is valid key
-	IsValidKey string `json:"isValidKey,omitempty"`
+	IsValidKey bool `json:"isValidKey,omitempty"`
 }
 
 type CompanyDetails struct {
diff --git a/accessEntity/data.go b/accessEntity/data.go
index 3961d87..70b3ca9 100644
--- a/accessEntity/data.go
+++ b/accessEntity/data.go
@@ -15,6 +15,7 @@
 
 import (
 	"database/sql"
+	"fmt"
 	"github.com/apid/apidVerifyApiKey/common"
 	"strings"
 )
@@ -29,50 +30,29 @@
 	common.DbManager
 }
 
-func (d *DbManager) GetOrgName(tenantId string) (string, error) {
-	row := d.GetDb().QueryRow(sql_select_org, tenantId)
-	org := sql.NullString{}
-	if err := row.Scan(&org); err != nil {
-		return "", err
+func (d *DbManager) GetApiProductNames(id string, idType string) ([]string, error) {
+	var query string
+	switch idType {
+	case TypeConsumerKey:
+		query = selectApiProductsById(
+			selectAppCredentialMapperByConsumerKey(
+				"'"+id+"'",
+				"apiprdt_id",
+			),
+			"name",
+		)
+	case TypeApp:
+		query = selectApiProductsById(
+			selectAppCredentialMapperByAppId(
+				"'"+id+"'",
+				"apiprdt_id",
+			),
+			"name",
+		)
+	default:
+		return nil, fmt.Errorf("unsupported idType")
 	}
-	if org.Valid {
-		return org.String, nil
-	}
-	return "", nil
-}
 
-func (d *DbManager) GetApiProductNamesByAppId(appId string) ([]string, error) {
-	query := selectApiProductsById(
-		selectAppCredentialMapperByAppId(
-			"'"+appId+"'",
-			"apiprdt_id",
-		),
-		"name",
-	)
-	rows, err := d.GetDb().Query(query)
-	if err != nil {
-		return nil, err
-	}
-	defer rows.Close()
-	var names []string
-	for rows.Next() {
-		name := sql.NullString{}
-		err = rows.Scan(&name)
-		if err != nil {
-			return nil, err
-		}
-		if name.Valid {
-			names = append(names, name.String)
-		}
-	}
-	return names, nil
-}
-
-func (d *DbManager) GetAppNamesByComId(comId string) ([]string, error) {
-	query := selectAppByComId(
-		"'"+comId+"'",
-		"name",
-	)
 	rows, err := d.GetDb().Query(query)
 	if err != nil {
 		return nil, err
@@ -118,14 +98,26 @@
 	return email.String, nil
 }
 
-func (d *DbManager) GetComNamesByDevId(devId string) ([]string, error) {
-	query := selectCompanyByComId(
-		selectCompanyDeveloperByDevId(
-			"'"+devId+"'",
-			"company_id",
-		),
-		"name",
-	)
+func (d *DbManager) GetComNames(id string, idType string) ([]string, error) {
+	var query string
+	switch idType {
+	case TypeDeveloper:
+		query = selectCompanyByComId(
+			selectCompanyDeveloperByDevId(
+				"'"+id+"'",
+				"company_id",
+			),
+			"name",
+		)
+	case TypeCompany:
+		query = selectCompanyByComId(
+			"'"+id+"'",
+			"name",
+		)
+	default:
+		return nil, fmt.Errorf("unsupported idType")
+	}
+
 	rows, err := d.GetDb().Query(query)
 	if err != nil {
 		return nil, err
@@ -145,11 +137,22 @@
 	return names, nil
 }
 
-func (d *DbManager) GetAppNamesByDevId(devId string) ([]string, error) {
-	query := selectAppByDevId(
-		"'"+devId+"'",
-		"name",
-	)
+func (d *DbManager) GetAppNames(id string, t string) ([]string, error) {
+	var query string
+	switch t {
+	case TypeDeveloper:
+		query = selectAppByDevId(
+			"'"+id+"'",
+			"name",
+		)
+	case TypeCompany:
+		query = selectAppByComId(
+			"'"+id+"'",
+			"name",
+		)
+	default:
+		return nil, fmt.Errorf("app type not supported")
+	}
 	rows, err := d.GetDb().Query(query)
 	if err != nil {
 		return nil, err
@@ -178,7 +181,7 @@
 			"status",
 		)
 	case AppTypeCompany:
-		query = selectDeveloperById(
+		query = selectCompanyByComId(
 			"'"+id+"'",
 			"status",
 		)
diff --git a/accessEntity/data_test.go b/accessEntity/data_test.go
index fc50947..914b7e1 100644
--- a/accessEntity/data_test.go
+++ b/accessEntity/data_test.go
@@ -44,348 +44,433 @@
 				},
 			}
 			dbMan.SetDbVersion(dataTestTempDir)
+			setupTestDb(dbMan.GetDb())
 		})
 
-		It("should get apiProducts", func() {
-			setupTestDb(dbMan.GetDb())
-			testData := [][]string{
-				//positive tests
-				{IdentifierApiProductName, "apstest", "", "", "apid-haoming"},
-				{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "apid-haoming"},
-				{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", IdentifierApiResource, "/**", "apid-haoming"},
-				{IdentifierAppName, "apstest", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "abcd", IdentifierApiResource, "/**", "apid-haoming"},
-				{IdentifierAppName, "apstest", IdentifierDeveloperId, "e41f04e8-9d3f-470a-8bfd-c7939945896c", "apid-haoming"},
-				{IdentifierAppName, "apstest", IdentifierDeveloperEmail, "bar@google.com", "apid-haoming"},
-				{IdentifierAppName, "testappahhis", IdentifierCompanyName, "testcompanyhflxv", "apid-haoming"},
-				{IdentifierAppName, "apstest", IdentifierApiResource, "/**", "apid-haoming"},
-				// negative tests
-				{IdentifierApiProductName, "apstest", "", "", "non-existent"},
-				{IdentifierApiProductName, "non-existent", "", "", "apid-haoming"},
-				{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
-				{IdentifierAppId, "non-existent", IdentifierApiResource, "non-existent", "apid-haoming"},
-				{IdentifierAppName, "non-existent", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "non-existent", IdentifierApiResource, "non-existent", "apid-haoming"},
-				{IdentifierAppName, "non-existent", IdentifierDeveloperId, "non-existent", "apid-haoming"},
-				{IdentifierAppName, "non-existent", IdentifierDeveloperEmail, "non-existent", "apid-haoming"},
-				{IdentifierAppName, "non-existent", IdentifierCompanyName, "non-existent", "apid-haoming"},
-				{IdentifierAppName, "non-existent", IdentifierApiResource, "non-existent", "apid-haoming"},
-			}
-
-			var expectedDevApiProd = common.ApiProduct{
-				Id:            "b7e0970c-4677-4b05-8105-5ea59fdcf4e7",
-				Name:          "apstest",
-				DisplayName:   "apstest",
-				Description:   "",
-				ApiResources:  "{/**}",
-				ApprovalType:  "AUTO",
-				Scopes:        `{""}`,
-				Proxies:       `{aps,perfBenchmark}`,
-				Environments:  `{prod,test}`,
-				Quota:         "10000000",
-				QuotaTimeUnit: "MINUTE",
-				QuotaInterval: 1,
-				CreatedAt:     "2017-08-18 22:12:49.363+00:00",
-				CreatedBy:     "haoming@apid.git",
-				UpdatedAt:     "2017-08-18 22:26:50.153+00:00",
-				UpdatedBy:     "haoming@apid.git",
-				TenantId:      "515211e9",
-			}
-
-			var expectedComApiProd = common.ApiProduct{
-				Id:            "fea8a6d5-8d34-477f-ac82-c397eaec06af",
-				Name:          "testproductsdljnkpt",
-				DisplayName:   "testproductsdljnkpt",
-				Description:   "",
-				ApiResources:  "{/res1}",
-				ApprovalType:  "AUTO",
-				Scopes:        `{}`,
-				Proxies:       `{}`,
-				Environments:  `{test}`,
-				Quota:         "",
-				QuotaTimeUnit: "",
-				QuotaInterval: 0,
-				CreatedAt:     "2017-11-02 16:00:15.608+00:00",
-				CreatedBy:     "haoming@apid.git",
-				UpdatedAt:     "2017-11-02 16:00:18.125+00:00",
-				UpdatedBy:     "haoming@apid.git",
-				TenantId:      "515211e9",
-			}
-
-			results := [][]common.ApiProduct{
-				{expectedDevApiProd},
-				{expectedDevApiProd},
-				{expectedDevApiProd},
-				{expectedDevApiProd},
-				{expectedDevApiProd},
-				{expectedDevApiProd},
-				{expectedDevApiProd},
-				{expectedDevApiProd},
-				{expectedComApiProd},
-				{expectedDevApiProd},
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-			}
-
-			for i, data := range testData {
-				priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
-				prods, err := dbMan.GetApiProducts(org, priKey, priVal, secKey, secVal)
-				Expect(err).Should(Succeed())
-				if len(results[i]) > 0 {
-					Expect(prods).Should(Equal(results[i]))
-				} else {
-					Expect(prods).Should(BeZero())
+		Describe("Get structs", func() {
+			It("should get apiProducts", func() {
+				testData := [][]string{
+					//positive tests
+					{IdentifierApiProductName, "apstest", "", "", "apid-haoming"},
+					{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "apid-haoming"},
+					{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", IdentifierApiResource, "/**", "apid-haoming"},
+					{IdentifierAppName, "apstest", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "abcd", IdentifierApiResource, "/**", "apid-haoming"},
+					{IdentifierAppName, "apstest", IdentifierDeveloperId, "e41f04e8-9d3f-470a-8bfd-c7939945896c", "apid-haoming"},
+					{IdentifierAppName, "apstest", IdentifierDeveloperEmail, "bar@google.com", "apid-haoming"},
+					{IdentifierAppName, "testappahhis", IdentifierCompanyName, "testcompanyhflxv", "apid-haoming"},
+					{IdentifierAppName, "apstest", IdentifierApiResource, "/**", "apid-haoming"},
+					// negative tests
+					{IdentifierApiProductName, "apstest", "", "", "non-existent"},
+					{IdentifierApiProductName, "non-existent", "", "", "apid-haoming"},
+					{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
+					{IdentifierAppId, "non-existent", IdentifierApiResource, "non-existent", "apid-haoming"},
+					{IdentifierAppName, "non-existent", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "non-existent", IdentifierApiResource, "non-existent", "apid-haoming"},
+					{IdentifierAppName, "non-existent", IdentifierDeveloperId, "non-existent", "apid-haoming"},
+					{IdentifierAppName, "non-existent", IdentifierDeveloperEmail, "non-existent", "apid-haoming"},
+					{IdentifierAppName, "non-existent", IdentifierCompanyName, "non-existent", "apid-haoming"},
+					{IdentifierAppName, "non-existent", IdentifierApiResource, "non-existent", "apid-haoming"},
 				}
-			}
+
+				var expectedDevApiProd = common.ApiProduct{
+					Id:            "b7e0970c-4677-4b05-8105-5ea59fdcf4e7",
+					Name:          "apstest",
+					DisplayName:   "apstest",
+					Description:   "",
+					ApiResources:  "{/**}",
+					ApprovalType:  "AUTO",
+					Scopes:        `{""}`,
+					Proxies:       `{aps,perfBenchmark}`,
+					Environments:  `{prod,test}`,
+					Quota:         "10000000",
+					QuotaTimeUnit: "MINUTE",
+					QuotaInterval: 1,
+					CreatedAt:     "2017-08-18 22:12:49.363+00:00",
+					CreatedBy:     "haoming@apid.git",
+					UpdatedAt:     "2017-08-18 22:26:50.153+00:00",
+					UpdatedBy:     "haoming@apid.git",
+					TenantId:      "515211e9",
+				}
+
+				var expectedComApiProd = common.ApiProduct{
+					Id:            "fea8a6d5-8d34-477f-ac82-c397eaec06af",
+					Name:          "testproductsdljnkpt",
+					DisplayName:   "testproductsdljnkpt",
+					Description:   "",
+					ApiResources:  "{/res1}",
+					ApprovalType:  "AUTO",
+					Scopes:        `{}`,
+					Proxies:       `{}`,
+					Environments:  `{test}`,
+					Quota:         "",
+					QuotaTimeUnit: "",
+					QuotaInterval: 0,
+					CreatedAt:     "2017-11-02 16:00:15.608+00:00",
+					CreatedBy:     "haoming@apid.git",
+					UpdatedAt:     "2017-11-02 16:00:18.125+00:00",
+					UpdatedBy:     "haoming@apid.git",
+					TenantId:      "515211e9",
+				}
+
+				results := [][]common.ApiProduct{
+					{expectedDevApiProd},
+					{expectedDevApiProd},
+					{expectedDevApiProd},
+					{expectedDevApiProd},
+					{expectedDevApiProd},
+					{expectedDevApiProd},
+					{expectedDevApiProd},
+					{expectedDevApiProd},
+					{expectedComApiProd},
+					{expectedDevApiProd},
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+				}
+
+				for i, data := range testData {
+					priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
+					prods, err := dbMan.GetApiProducts(org, priKey, priVal, secKey, secVal)
+					Expect(err).Should(Succeed())
+					if len(results[i]) > 0 {
+						Expect(prods).Should(Equal(results[i]))
+					} else {
+						Expect(prods).Should(BeZero())
+					}
+				}
+			})
+
+			It("should get apps", func() {
+				testData := [][]string{
+					//positive tests
+					{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "apid-haoming"},
+					{IdentifierAppName, "apstest", "", "", "apid-haoming"},
+					{IdentifierAppName, "apstest", IdentifierDeveloperId, "e41f04e8-9d3f-470a-8bfd-c7939945896c", "apid-haoming"},
+					{IdentifierAppName, "apstest", IdentifierDeveloperEmail, "bar@google.com", "apid-haoming"},
+					{IdentifierAppName, "testappahhis", IdentifierCompanyName, "testcompanyhflxv", "apid-haoming"},
+					{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
+					// negative tests
+					{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "non-existent"},
+					{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
+					{IdentifierAppName, "non-existent", "", "", "apid-haoming"},
+					{IdentifierAppName, "non-existent", IdentifierDeveloperId, "non-existent", "apid-haoming"},
+					{IdentifierAppName, "non-existent", IdentifierDeveloperEmail, "non-existent", "apid-haoming"},
+					{IdentifierAppName, "non-existent", IdentifierCompanyName, "non-existent", "apid-haoming"},
+					{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
+				}
+
+				var expectedDevApp = common.App{
+					Id:          "408ad853-3fa0-402f-90ee-103de98d71a5",
+					TenantId:    "515211e9",
+					Name:        "apstest",
+					DisplayName: "apstest",
+					AccessType:  "READ",
+					CallbackUrl: "https://www.google.com",
+					Status:      "APPROVED",
+					AppFamily:   "default",
+					CompanyId:   "",
+					DeveloperId: "e41f04e8-9d3f-470a-8bfd-c7939945896c",
+					ParentId:    "e41f04e8-9d3f-470a-8bfd-c7939945896c",
+					Type:        "DEVELOPER",
+					CreatedAt:   "2017-08-18 22:13:18.325+00:00",
+					CreatedBy:   "haoming@apid.git",
+					UpdatedAt:   "2017-08-18 22:13:18.325+00:00",
+					UpdatedBy:   "haoming@apid.git",
+				}
+
+				var expectedComApp = common.App{
+					Id:          "35608afe-2715-4064-bb4d-3cbb4e82c474",
+					TenantId:    "515211e9",
+					Name:        "testappahhis",
+					DisplayName: "testappahhis",
+					AccessType:  "READ",
+					CallbackUrl: "",
+					Status:      "APPROVED",
+					AppFamily:   "default",
+					CompanyId:   "a94f75e2-69b0-44af-8776-155df7c7d22e",
+					DeveloperId: "",
+					ParentId:    "a94f75e2-69b0-44af-8776-155df7c7d22e",
+					Type:        "COMPANY",
+					CreatedAt:   "2017-11-02 16:00:16.504+00:00",
+					CreatedBy:   "haoming@apid.git",
+					UpdatedAt:   "2017-11-02 16:00:16.504+00:00",
+					UpdatedBy:   "haoming@apid.git",
+				}
+
+				results := [][]common.App{
+					{expectedDevApp},
+					{expectedDevApp},
+					{expectedDevApp},
+					{expectedDevApp},
+					{expectedComApp},
+					{expectedDevApp},
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+				}
+
+				for i, data := range testData {
+					priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
+					apps, err := dbMan.GetApps(org, priKey, priVal, secKey, secVal)
+					Expect(err).Should(Succeed())
+					if len(results[i]) > 0 {
+						Expect(apps).Should(Equal(results[i]))
+					} else {
+						Expect(apps).Should(BeZero())
+					}
+				}
+			})
+
+			It("should get Companies", func() {
+				testData := [][]string{
+					//positive tests
+					{IdentifierAppId, "35608afe-2715-4064-bb4d-3cbb4e82c474", "", "", "apid-haoming"},
+					{IdentifierCompanyName, "testcompanyhflxv", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "wxyz", "", "", "apid-haoming"},
+					// negative tests
+					{IdentifierAppId, "35608afe-2715-4064-bb4d-3cbb4e82c474", "", "", "non-existent"},
+					{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
+					{IdentifierCompanyName, "non-existent", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
+				}
+
+				var expectedCom = common.Company{
+					Id:          "a94f75e2-69b0-44af-8776-155df7c7d22e",
+					TenantId:    "515211e9",
+					Name:        "testcompanyhflxv",
+					DisplayName: "testcompanyhflxv",
+					Status:      "ACTIVE",
+					CreatedAt:   "2017-11-02 16:00:16.287+00:00",
+					CreatedBy:   "haoming@apid.git",
+					UpdatedAt:   "2017-11-02 16:00:16.287+00:00",
+					UpdatedBy:   "haoming@apid.git",
+				}
+
+				results := [][]common.Company{
+					{expectedCom},
+					{expectedCom},
+					{expectedCom},
+					nil,
+					nil,
+					nil,
+					nil,
+				}
+
+				for i, data := range testData {
+					priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
+					apps, err := dbMan.GetCompanies(org, priKey, priVal, secKey, secVal)
+					Expect(err).Should(Succeed())
+					if len(results[i]) > 0 {
+						Expect(apps).Should(Equal(results[i]))
+					} else {
+						Expect(apps).Should(BeZero())
+					}
+				}
+			})
+
+			It("should get developers", func() {
+				testData := [][]string{
+					//positive tests
+					{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
+					{IdentifierDeveloperEmail, "bar@google.com", "", "", "apid-haoming"},
+					{IdentifierDeveloperId, "e41f04e8-9d3f-470a-8bfd-c7939945896c", "", "", "apid-haoming"},
+
+					// negative tests
+					{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "non-existent"},
+					{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
+					{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
+					{IdentifierDeveloperEmail, "non-existent", "", "", "apid-haoming"},
+					{IdentifierDeveloperId, "non-existent", "", "", "apid-haoming"},
+				}
+
+				var expectedDev = common.Developer{
+					Id:                "e41f04e8-9d3f-470a-8bfd-c7939945896c",
+					TenantId:          "515211e9",
+					UserName:          "haoming",
+					FirstName:         "haoming",
+					LastName:          "zhang",
+					Password:          "",
+					Email:             "bar@google.com",
+					Status:            "ACTIVE",
+					EncryptedPassword: "",
+					Salt:              "",
+					CreatedAt:         "2017-08-16 22:39:46.669+00:00",
+					CreatedBy:         "foo@google.com",
+					UpdatedAt:         "2017-08-16 22:39:46.669+00:00",
+					UpdatedBy:         "foo@google.com",
+				}
+
+				results := [][]common.Developer{
+					{expectedDev},
+					{expectedDev},
+					{expectedDev},
+					{expectedDev},
+					nil,
+					nil,
+					nil,
+					nil,
+					nil,
+				}
+
+				for i, data := range testData {
+					priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
+					prods, err := dbMan.GetDevelopers(org, priKey, priVal, secKey, secVal)
+					Expect(err).Should(Succeed())
+					if len(results[i]) > 0 {
+						Expect(prods).Should(Equal(results[i]))
+					} else {
+						Expect(prods).Should(BeZero())
+					}
+				}
+			})
+
+			It("should get appCredentials", func() {
+				testData := [][]string{
+					// positive tests
+					{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
+
+					// negative tests
+					{IdentifierConsumerKey, "abcd", "", "", "non-existent"},
+					{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
+				}
+
+				var expectedCred = common.AppCredential{
+					Id:             "abcd",
+					TenantId:       "515211e9",
+					ConsumerSecret: "secret1",
+					AppId:          "408ad853-3fa0-402f-90ee-103de98d71a5",
+					MethodType:     "",
+					Status:         "APPROVED",
+					IssuedAt:       "2017-08-18 22:13:18.35+00:00",
+					ExpiresAt:      "",
+					AppStatus:      "",
+					Scopes:         "{}",
+					CreatedAt:      "2017-08-18 22:13:18.35+00:00",
+					CreatedBy:      "-NA-",
+					UpdatedAt:      "2017-08-18 22:13:18.352+00:00",
+					UpdatedBy:      "-NA-",
+				}
+
+				results := [][]common.AppCredential{
+					{expectedCred},
+					nil,
+					nil,
+				}
+
+				for i, data := range testData {
+					priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
+					prods, err := dbMan.GetAppCredentials(org, priKey, priVal, secKey, secVal)
+					Expect(err).Should(Succeed())
+					if len(results[i]) > 0 {
+						Expect(prods).Should(Equal(results[i]))
+					} else {
+						Expect(prods).Should(BeZero())
+					}
+				}
+			})
+
+			It("should get CompanyDevelopers", func() {
+				testData := [][]string{
+					// positive tests
+					{IdentifierCompanyName, "testcompanyhflxv", "", "", "apid-haoming"},
+
+					// negative tests
+					{IdentifierCompanyName, "testcompanyhflxv", "", "", "non-existent"},
+					{IdentifierCompanyName, "non-existent", "", "", "apid-haoming"},
+				}
+
+				var expectedComDev = common.CompanyDeveloper{
+					TenantId:    "515211e9",
+					CompanyId:   "a94f75e2-69b0-44af-8776-155df7c7d22e",
+					DeveloperId: "590f33bf-f05c-48c1-bb93-183759bd9ee1",
+					Roles:       "admin",
+					CreatedAt:   "2017-11-02 16:00:16.287+00:00",
+					CreatedBy:   "haoming@apid.git",
+					UpdatedAt:   "2017-11-02 16:00:16.287+00:00",
+					UpdatedBy:   "haoming@apid.git",
+				}
+
+				results := [][]common.CompanyDeveloper{
+					{expectedComDev},
+					nil,
+					nil,
+				}
+
+				for i, data := range testData {
+					priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
+					prods, err := dbMan.GetCompanyDevelopers(org, priKey, priVal, secKey, secVal)
+					Expect(err).Should(Succeed())
+					if len(results[i]) > 0 {
+						Expect(prods).Should(Equal(results[i]))
+					} else {
+						Expect(prods).Should(BeZero())
+					}
+				}
+			})
+
 		})
 
-		It("should get apps", func() {
-			setupTestDb(dbMan.GetDb())
-			testData := [][]string{
-				//positive tests
-				{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "apid-haoming"},
-				{IdentifierAppName, "apstest", "", "", "apid-haoming"},
-				{IdentifierAppName, "apstest", IdentifierDeveloperId, "e41f04e8-9d3f-470a-8bfd-c7939945896c", "apid-haoming"},
-				{IdentifierAppName, "apstest", IdentifierDeveloperEmail, "bar@google.com", "apid-haoming"},
-				{IdentifierAppName, "testappahhis", IdentifierCompanyName, "testcompanyhflxv", "apid-haoming"},
-				{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
-				// negative tests
-				{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "non-existent"},
-				{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
-				{IdentifierAppName, "non-existent", "", "", "apid-haoming"},
-				{IdentifierAppName, "non-existent", IdentifierDeveloperId, "non-existent", "apid-haoming"},
-				{IdentifierAppName, "non-existent", IdentifierDeveloperEmail, "non-existent", "apid-haoming"},
-				{IdentifierAppName, "non-existent", IdentifierCompanyName, "non-existent", "apid-haoming"},
-				{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
-			}
+		Describe("utils", func() {
+			It("GetApiProductNamesByConsumerKey", func() {
+				data := "abcd"
+				expected := []string{"apstest"}
+				Expect(dbMan.GetApiProductNames(data, TypeConsumerKey)).Should(Equal(expected))
 
-			var expectedDevApp = common.App{
-				Id:          "408ad853-3fa0-402f-90ee-103de98d71a5",
-				TenantId:    "515211e9",
-				Name:        "apstest",
-				DisplayName: "apstest",
-				AccessType:  "READ",
-				CallbackUrl: "https://www.google.com",
-				Status:      "APPROVED",
-				AppFamily:   "default",
-				CompanyId:   "",
-				DeveloperId: "e41f04e8-9d3f-470a-8bfd-c7939945896c",
-				ParentId:    "e41f04e8-9d3f-470a-8bfd-c7939945896c",
-				Type:        "DEVELOPER",
-				CreatedAt:   "2017-08-18 22:13:18.325+00:00",
-				CreatedBy:   "haoming@apid.git",
-				UpdatedAt:   "2017-08-18 22:13:18.325+00:00",
-				UpdatedBy:   "haoming@apid.git",
-			}
+				data = "408ad853-3fa0-402f-90ee-103de98d71a5"
+				expected = []string{"apstest"}
+				Expect(dbMan.GetApiProductNames(data, TypeApp)).Should(Equal(expected))
+			})
 
-			var expectedComApp = common.App{
-				Id:          "35608afe-2715-4064-bb4d-3cbb4e82c474",
-				TenantId:    "515211e9",
-				Name:        "testappahhis",
-				DisplayName: "testappahhis",
-				AccessType:  "READ",
-				CallbackUrl: "",
-				Status:      "APPROVED",
-				AppFamily:   "default",
-				CompanyId:   "a94f75e2-69b0-44af-8776-155df7c7d22e",
-				DeveloperId: "",
-				ParentId:    "a94f75e2-69b0-44af-8776-155df7c7d22e",
-				Type:        "COMPANY",
-				CreatedAt:   "2017-11-02 16:00:16.504+00:00",
-				CreatedBy:   "haoming@apid.git",
-				UpdatedAt:   "2017-11-02 16:00:16.504+00:00",
-				UpdatedBy:   "haoming@apid.git",
-			}
+			It("GetAppNames", func() {
+				data := "a94f75e2-69b0-44af-8776-155df7c7d22e"
+				expected := []string{"testappahhis"}
+				Expect(dbMan.GetAppNames(data, TypeCompany)).Should(Equal(expected))
 
-			results := [][]common.App{
-				{expectedDevApp},
-				{expectedDevApp},
-				{expectedDevApp},
-				{expectedDevApp},
-				{expectedComApp},
-				{expectedDevApp},
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-			}
+				data = "e41f04e8-9d3f-470a-8bfd-c7939945896c"
+				expected = []string{"apstest"}
+				Expect(dbMan.GetAppNames(data, TypeDeveloper)).Should(Equal(expected))
+			})
 
-			for i, data := range testData {
-				priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
-				apps, err := dbMan.GetApps(org, priKey, priVal, secKey, secVal)
-				Expect(err).Should(Succeed())
-				if len(results[i]) > 0 {
-					Expect(apps).Should(Equal(results[i]))
-				} else {
-					Expect(apps).Should(BeZero())
-				}
-			}
-		})
+			It("GetComNames", func() {
+				data := "8ba5b747-5104-4a40-89ca-a0a51798fe34"
+				expected := []string{"DevCompany"}
+				Expect(dbMan.GetComNames(data, TypeCompany)).Should(Equal(expected))
+				data = "590f33bf-f05c-48c1-bb93-183759bd9ee1"
+				expected = []string{"testcompanyhflxv"}
+				Expect(dbMan.GetComNames(data, TypeDeveloper)).Should(Equal(expected))
+			})
 
-		It("should get Companies", func() {
-			setupTestDb(dbMan.GetDb())
-			testData := [][]string{
-				//positive tests
-				{IdentifierAppId, "35608afe-2715-4064-bb4d-3cbb4e82c474", "", "", "apid-haoming"},
-				{IdentifierCompanyName, "testcompanyhflxv", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "wxyz", "", "", "apid-haoming"},
-				// negative tests
-				{IdentifierAppId, "35608afe-2715-4064-bb4d-3cbb4e82c474", "", "", "non-existent"},
-				{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
-				{IdentifierCompanyName, "non-existent", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
-			}
+			It("GetDevEmailByDevId", func() {
+				data := "e41f04e8-9d3f-470a-8bfd-c7939945896c"
+				expected := "bar@google.com"
+				Expect(dbMan.GetDevEmailByDevId(data)).Should(Equal(expected))
+			})
 
-			var expectedCom = common.Company{
-				Id:          "a94f75e2-69b0-44af-8776-155df7c7d22e",
-				TenantId:    "515211e9",
-				Name:        "testcompanyhflxv",
-				DisplayName: "testcompanyhflxv",
-				Status:      "ACTIVE",
-				CreatedAt:   "2017-11-02 16:00:16.287+00:00",
-				CreatedBy:   "haoming@apid.git",
-				UpdatedAt:   "2017-11-02 16:00:16.287+00:00",
-				UpdatedBy:   "haoming@apid.git",
-			}
+			It("GetStatus", func() {
+				data := "e41f04e8-9d3f-470a-8bfd-c7939945896c"
+				expected := "ACTIVE"
+				Expect(dbMan.GetStatus(data, AppTypeDeveloper)).Should(Equal(expected))
+				data = "8ba5b747-5104-4a40-89ca-a0a51798fe34"
+				expected = "ACTIVE"
+				Expect(dbMan.GetStatus(data, AppTypeCompany)).Should(Equal(expected))
+			})
 
-			results := [][]common.Company{
-				{expectedCom},
-				{expectedCom},
-				{expectedCom},
-				nil,
-				nil,
-				nil,
-				nil,
-			}
-
-			for i, data := range testData {
-				priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
-				apps, err := dbMan.GetCompanies(org, priKey, priVal, secKey, secVal)
-				Expect(err).Should(Succeed())
-				if len(results[i]) > 0 {
-					Expect(apps).Should(Equal(results[i]))
-				} else {
-					Expect(apps).Should(BeZero())
-				}
-			}
-		})
-
-		It("should get developers", func() {
-			setupTestDb(dbMan.GetDb())
-			testData := [][]string{
-				//positive tests
-				{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
-				{IdentifierDeveloperEmail, "bar@google.com", "", "", "apid-haoming"},
-				{IdentifierDeveloperId, "e41f04e8-9d3f-470a-8bfd-c7939945896c", "", "", "apid-haoming"},
-
-				// negative tests
-				{IdentifierAppId, "408ad853-3fa0-402f-90ee-103de98d71a5", "", "", "non-existent"},
-				{IdentifierAppId, "non-existent", "", "", "apid-haoming"},
-				{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
-				{IdentifierDeveloperEmail, "non-existent", "", "", "apid-haoming"},
-				{IdentifierDeveloperId, "non-existent", "", "", "apid-haoming"},
-			}
-
-			var expectedDev = common.Developer{
-				Id:                "e41f04e8-9d3f-470a-8bfd-c7939945896c",
-				TenantId:          "515211e9",
-				UserName:          "haoming",
-				FirstName:         "haoming",
-				LastName:          "zhang",
-				Password:          "",
-				Email:             "bar@google.com",
-				Status:            "ACTIVE",
-				EncryptedPassword: "",
-				Salt:              "",
-				CreatedAt:         "2017-08-16 22:39:46.669+00:00",
-				CreatedBy:         "foo@google.com",
-				UpdatedAt:         "2017-08-16 22:39:46.669+00:00",
-				UpdatedBy:         "foo@google.com",
-			}
-
-			results := [][]common.Developer{
-				{expectedDev},
-				{expectedDev},
-				{expectedDev},
-				{expectedDev},
-				nil,
-				nil,
-				nil,
-				nil,
-				nil,
-			}
-
-			for i, data := range testData {
-				priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
-				prods, err := dbMan.GetDevelopers(org, priKey, priVal, secKey, secVal)
-				Expect(err).Should(Succeed())
-				if len(results[i]) > 0 {
-					Expect(prods).Should(Equal(results[i]))
-				} else {
-					Expect(prods).Should(BeZero())
-				}
-			}
-		})
-
-		It("should get appCredentials", func() {
-			setupTestDb(dbMan.GetDb())
-			testData := [][]string{
-				// positive tests
-				{IdentifierConsumerKey, "abcd", "", "", "apid-haoming"},
-
-				// negative tests
-				{IdentifierConsumerKey, "abcd", "", "", "non-existent"},
-				{IdentifierConsumerKey, "non-existent", "", "", "apid-haoming"},
-			}
-
-			var expectedCred = common.AppCredential{
-				Id:             "abcd",
-				TenantId:       "515211e9",
-				ConsumerSecret: "secret1",
-				AppId:          "408ad853-3fa0-402f-90ee-103de98d71a5",
-				MethodType:     "",
-				Status:         "APPROVED",
-				IssuedAt:       "2017-08-18 22:13:18.35+00:00",
-				ExpiresAt:      "",
-				AppStatus:      "",
-				Scopes:         "{}",
-				CreatedAt:      "2017-08-18 22:13:18.35+00:00",
-				CreatedBy:      "-NA-",
-				UpdatedAt:      "2017-08-18 22:13:18.352+00:00",
-				UpdatedBy:      "-NA-",
-			}
-
-			results := [][]common.AppCredential{
-				{expectedCred},
-				nil,
-				nil,
-			}
-
-			for i, data := range testData {
-				priKey, priVal, secKey, secVal, org := data[0], data[1], data[2], data[3], data[4]
-				prods, err := dbMan.GetAppCredentials(org, priKey, priVal, secKey, secVal)
-				Expect(err).Should(Succeed())
-				if len(results[i]) > 0 {
-					Expect(prods).Should(Equal(results[i]))
-				} else {
-					Expect(prods).Should(BeZero())
-				}
-			}
 		})
 
 	})
diff --git a/accessEntity/data_test.sql b/accessEntity/data_test.sql
index 2a41ad7..8b1590a 100644
--- a/accessEntity/data_test.sql
+++ b/accessEntity/data_test.sql
@@ -1,3 +1,17 @@
+-- Copyright 2017 Google Inc.
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+--      http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+
 PRAGMA foreign_keys=OFF;
 BEGIN TRANSACTION;
 CREATE TABLE kms_app (id text,tenant_id text,name text,display_name text,access_type text,callback_url text,status text,app_family text,company_id text,developer_id text,parent_id text,type text,created_at blob,created_by text,updated_at blob,updated_by text,_change_selector text, primary key (id,tenant_id));
@@ -20,6 +34,7 @@
 INSERT INTO "kms_company" VALUES('8ba5b747-5104-4a40-89ca-a0a51798fe34','515211e9','DevCompany','East India Company','ACTIVE','2017-08-15 03:29:02.449+00:00','haoming@apid.git','2017-08-15 03:29:02.449+00:00','haoming@apid.git','515211e9');
 INSERT INTO "kms_company" VALUES('a94f75e2-69b0-44af-8776-155df7c7d22e','515211e9','testcompanyhflxv','testcompanyhflxv','ACTIVE','2017-11-02 16:00:16.287+00:00','haoming@apid.git','2017-11-02 16:00:16.287+00:00','haoming@apid.git','515211e9');
 CREATE TABLE kms_company_developer (tenant_id text,company_id text,developer_id text,roles text,created_at blob,created_by text,updated_at blob,updated_by text,_change_selector text, primary key (tenant_id,company_id,developer_id));
+INSERT INTO "kms_company_developer" VALUES('515211e9','a94f75e2-69b0-44af-8776-155df7c7d22e','590f33bf-f05c-48c1-bb93-183759bd9ee1','admin','2017-11-02 16:00:16.287+00:00','haoming@apid.git','2017-11-02 16:00:16.287+00:00','haoming@apid.git','515211e9');
 CREATE TABLE kms_developer (id text,tenant_id text,username text,first_name text,last_name text,password text,email text,status text,encrypted_password text,salt text,created_at blob,created_by text,updated_at blob,updated_by text,_change_selector text, primary key (id,tenant_id));
 INSERT INTO "kms_developer" VALUES('e41f04e8-9d3f-470a-8bfd-c7939945896c','515211e9','haoming','haoming','zhang','','bar@google.com','ACTIVE','','','2017-08-16 22:39:46.669+00:00','foo@google.com','2017-08-16 22:39:46.669+00:00','foo@google.com','515211e9');
 INSERT INTO "kms_developer" VALUES('47d862db-884f-4b8e-9649-fe6d0be1a739','515211e9','qwe','qwe','qwe','','barfoo@google.com','ACTIVE','','','2017-10-12 19:12:48.306+00:00','haoming@apid.git','2017-10-12 19:12:48.306+00:00','haoming@apid.git','515211e9');
diff --git a/accessEntity/interfaces.go b/accessEntity/interfaces.go
index e77c981..a580762 100644
--- a/accessEntity/interfaces.go
+++ b/accessEntity/interfaces.go
@@ -1,3 +1,16 @@
+// Copyright 2017 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
 package accessEntity
 
 import (
@@ -19,12 +32,9 @@
 	GetAppCredentials(org, priKey, priVal, secKey, secVal string) (appCredentials []common.AppCredential, err error)
 	GetDevelopers(org, priKey, priVal, secKey, secVal string) (developers []common.Developer, err error)
 	// utils
-	GetApiProductNamesByAppId(appId string) ([]string, error)
-	GetAppNamesByComId(comId string) ([]string, error)
-	GetComNamesByDevId(devId string) ([]string, error)
-	GetAppNamesByDevId(devId string) ([]string, error)
-	GetComNameByComId(comId string) (string, error)
+	GetApiProductNames(id string, idType string) ([]string, error)
+	GetAppNames(id string, idType string) ([]string, error)
+	GetComNames(id string, idType string) ([]string, error)
 	GetDevEmailByDevId(devId string) (string, error)
 	GetStatus(id, t string) (string, error)
-	GetOrgName(tenantId string) (string, error)
 }
diff --git a/common/api.go b/common/api.go
index 141e9fa..9b3f243 100644
--- a/common/api.go
+++ b/common/api.go
@@ -1,3 +1,16 @@
+// Copyright 2017 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
 package common
 
 import (
diff --git a/common/data.go b/common/data.go
index 9a824a8..61e2878 100644
--- a/common/data.go
+++ b/common/data.go
@@ -1,3 +1,16 @@
+// Copyright 2017 Google Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
 package common
 
 import (
@@ -55,7 +68,6 @@
 
 	db := dbc.Db
 	var attName, attValue, entity_id sql.NullString
-	// TODO : is there no other better way to do in caluse???
 	sql := sql_GET_KMS_ATTRIBUTES_FOR_TENANT + ` and entity_id in ('` + strings.Join(entities, `','`) + `')`
 	mapOfAttributes := make(map[string][]Attribute)
 	attributes, err := db.Query(sql, tenantId)