// Tests that a CommodityDTO is created with the arguments commodityType, key and used arguments // as its members . Tests that the created CommodityDTO is added to the Bought array in the // existing EntityDTO_CommodityBought struct with *ProviderId = * eb.currentProvider.Id // When find = false func TestBuys_False(t *testing.T) { assert := assert.New(t) entity := new(EntityDTO) providerIdStr := rand.String(5) entityDTOBuilder := &EntityDTOBuilder{ entity: entity, } providerDTO := new(ProviderDTO) providerDTO.Id = &providerIdStr entityDTOBuilder.currentProvider = providerDTO commType := new(CommodityDTO_CommodityType) key := rand.String(6) r := mathrand.New(mathrand.NewSource(99)) used := r.Float64() assert.Equal(0, len(entityDTOBuilder.entity.CommoditiesBought)) eb := entityDTOBuilder.Buys(*commType, key, used) // eb.GetCommoditiesBought => eb.CommoditiesBought type []*EntityDTO_CommodityBought assert.Equal(1, len(eb.entity.CommoditiesBought)) assert.Equal(commType, eb.entity.CommoditiesBought[0].Bought[0].CommodityType) assert.Equal(*commType, *eb.entity.CommoditiesBought[0].Bought[0].CommodityType) assert.Equal(&key, eb.entity.CommoditiesBought[0].Bought[0].Key) assert.Equal(key, *eb.entity.CommoditiesBought[0].Bought[0].Key) assert.Equal(&used, eb.entity.CommoditiesBought[0].Bought[0].Used) assert.Equal(used, *eb.entity.CommoditiesBought[0].Bought[0].Used) }
// Tests that NewProbeInfoBuilder creates a ProbeInfo struct with member variables set to the // arguments passed to it and creates a ProbeInfoBuilder struct with its probeInfo variable set // to the new ProbeInfo struct containing the passed arguments func TestNewProbeInfoBuilder(t *testing.T) { assert := assert.New(t) probeType := rand.String(6) probeCat := rand.String(7) var supplyCS []*sdk.TemplateDTO var acctDef []*AccountDefEntry probeInfoBldr := NewProbeInfoBuilder(probeType, probeCat, supplyCS, acctDef) assert.Equal(probeType, *probeInfoBldr.probeInfo.ProbeType) }
// Tests that the name and value passed as arguments to SetProperty are // appended to the array EntityProperties of eb.entity // Test case when eb.entity.GetEntityProperties != nil func TestSetProperty_notnil(t *testing.T) { assert := assert.New(t) entity := new(EntityDTO) name := rand.String(5) value := rand.String(6) entityDTOBuilder := &EntityDTOBuilder{ entity: entity, } eb := entityDTOBuilder.SetProperty(name, value) assert.Equal(&name, eb.entity.EntityProperties[0].Name) assert.Equal(name, *eb.entity.EntityProperties[0].Name) assert.Equal(&value, eb.entity.EntityProperties[0].Value) assert.Equal(value, *eb.entity.EntityProperties[0].Value) }
// Test to assert that the correct *EntityDTO_CommodityBought is returned if the // providerId for this struct is the same as the providerId passed to the method findCommBoughtProvider func TestFindCommBoughtProvider_False_inrange(t *testing.T) { assert := assert.New(t) entity := new(EntityDTO) providerIdStr := rand.String(5) currentProviderIdStr := rand.String(6) entityDTO_CommodityBought := new(EntityDTO_CommodityBought) entityDTO_CommodityBought.ProviderId = &providerIdStr // Bought array is len = 0 for this EntityDTO_CommodityBought entity.CommoditiesBought = append(entity.CommoditiesBought, entityDTO_CommodityBought) entityDTOBuilder := &EntityDTOBuilder{ entity: entity, } commBoughtProvider, wasFound := entityDTOBuilder.findCommBoughtProvider(¤tProviderIdStr) assert.Equal(false, wasFound) assert.Equal((*EntityDTO_CommodityBought)(nil), commBoughtProvider) }
// Tests that the name and description string arguments passed to ProbeEntityPropertyDef() are // used to set the Name and Description member variables of a newly created ExternalEntityLink_EntityPropertyDef // struct . // Tests that the created struct is appended to this.entityLink.ProbeEntityPropertyDef array func TestProbeEntityPropertyDef(t *testing.T) { assert := assert.New(t) externalEntityLink := new(ExternalEntityLink) externalEntityLinkBuilder := &ExternalEntityLinkBuilder{ entityLink: externalEntityLink, } name := rand.String(6) description := rand.String(6) assert.Equal(0, len(externalEntityLink.ProbeEntityPropertyDef)) eelb := externalEntityLinkBuilder.ProbeEntityPropertyDef(name, description) if assert.Equal(1, len(externalEntityLink.ProbeEntityPropertyDef)) { assert.Equal(&name, eelb.entityLink.ProbeEntityPropertyDef[0].Name) assert.Equal(name, *eelb.entityLink.ProbeEntityPropertyDef[0].Name) assert.Equal(&description, eelb.entityLink.ProbeEntityPropertyDef[0].Description) assert.Equal(description, *eelb.entityLink.ProbeEntityPropertyDef[0].Description) } }
// Tests that the name and value passed as arguments to SetProperty are // appended to the array EntityProperties of eb.entity // Test case when eb.entity.GetEntityProperties = nil func TestSetProperty_nil(t *testing.T) { assert := assert.New(t) entity := new(EntityDTO) name := rand.String(5) value := rand.String(6) entity.EntityProperties = nil entityDTOBuilder := &EntityDTOBuilder{ entity: entity, } assert.Equal([]*EntityDTO_EntityProperty(nil), entityDTOBuilder.entity.EntityProperties) //assert.Equal(([]*EntityDTO_EntityProperty)(nil), entityDTOBuilder.entity.EntityProperties) // assert.Nil(t, entityDTOBuilder.entity.EntityProperties) eb := entityDTOBuilder.SetProperty(name, value) assert.Equal(&name, eb.entity.EntityProperties[0].Name) assert.Equal(name, *eb.entity.EntityProperties[0].Name) assert.Equal(&value, eb.entity.EntityProperties[0].Value) assert.Equal(value, *eb.entity.EntityProperties[0].Value) }
// Tests that the getId() method returns a string pointer to // the Id member variable of the ProviderDTO struct that getId() is called on func TestGetId(t *testing.T) { assert := assert.New(t) fmt.Println("in TestProviderDTOProviderID") id := rand.String(5) providerDto := &ProviderDTO{ Id: &id, } assert.Equal(&id, providerDto.getId()) }
// Tests that the method NewAccountDefEntryBuilder creates an AccountDefEntry struct with member // variables set equal to the pointers to the arguments passed to it func TestNewAccountDefEntryBuilder(t *testing.T) { assert := assert.New(t) name := rand.String(6) displayName := rand.String(7) description := rand.String(8) verificationRegex := rand.String(9) entryType := AccountDefEntry_OPTIONAL isSecret := true acctDefEntryBuilder := NewAccountDefEntryBuilder(name, displayName, description, verificationRegex, entryType, isSecret) acctDef := acctDefEntryBuilder.accountDefEntry if assert.NotEqual((*AccountDefEntry)(nil), acctDef) { assert.Equal(name, *acctDef.Name) assert.Equal(displayName, *acctDef.DisplayName) assert.Equal(description, *acctDef.Description) assert.Equal(verificationRegex, *acctDef.VerificationRegex) assert.Equal(entryType, *acctDef.Type) assert.Equal(isSecret, *acctDef.IsSecret) } }
// test that the SetProvider method creates a ProviderDTO and sets its providerType and id to the // passed arguments func TestSetProvider(t *testing.T) { assert := assert.New(t) entityDTOBuilder := &EntityDTOBuilder{} pType := new(EntityDTO_EntityType) id := rand.String(6) eb := entityDTOBuilder.SetProvider(*pType, id) assert.Equal(pType, eb.currentProvider.providerType) assert.Equal(*pType, *eb.currentProvider.providerType) assert.Equal(&id, eb.currentProvider.Id) assert.Equal(id, *eb.currentProvider.Id) }
// Tests that the string passed to Matching() method is appended to the string array // variable called IdentifyProp in this.metaData func TestMatching(t *testing.T) { assert := assert.New(t) replacementEntityMD := new(EntityDTO_ReplacementEntityMetaData) replacementEMB := &ReplacementEntityMetaDataBuilder{ metaData: replacementEntityMD, } propStr := rand.String(6) rEMB := replacementEMB.Matching(propStr) assert.Equal(propStr, rEMB.metaData.IdentifyingProp[0]) assert.Equal(&propStr, &rEMB.metaData.IdentifyingProp[0]) }
// Tests method DisplayName() which sets the DisplayName of the entity member of the // EntityDTOBuilder that calls DisplayName() func TestDisplayName(t *testing.T) { assert := assert.New(t) entity := new(EntityDTO) entityDTOBuilder := &EntityDTOBuilder{ entity: entity, } dispName := rand.String(6) entityDTOBuilder.DisplayName(dispName) assert.Equal(&dispName, entityDTOBuilder.entity.DisplayName) assert.Equal(dispName, *entityDTOBuilder.entity.DisplayName) }
//Tests the method NewEntityDTOBuilder() , which should return a pointer to a EntityDTOBuilder //instance containing only its EntityDTOBuilder.entity member instantiated. func TestNewEntityDTOBuilder(t *testing.T) { assert := assert.New(t) pType := new(EntityDTO_EntityType) idstr := rand.String(5) entityDTOBuilder := NewEntityDTOBuilder(*pType, idstr) if assert.NotNil(t, entityDTOBuilder.entity) { assert.Equal(pType, entityDTOBuilder.entity.EntityType) assert.Equal(&idstr, entityDTOBuilder.entity.Id) if assert.NotNil(t, entityDTOBuilder.entity.CommoditiesBought) { assert.Equal(0, len(entityDTOBuilder.entity.CommoditiesBought)) } if assert.NotNil(t, entityDTOBuilder.entity.CommoditiesSold) { assert.Equal(0, len(entityDTOBuilder.entity.CommoditiesSold)) } } }
// Tests Sells() method which sets the CommodityType and key members of a new CommodityDTO instance // and appends the new CommodityDTO instance to the CommoditiesSold member array of the entity memb// er of the EntityDTOBuilder that calls this method. func TestSells(t *testing.T) { assert := assert.New(t) commType := new(CommodityDTO_CommodityType) keystr := rand.String(6) entity := new(EntityDTO) entityDTOBuilder := &EntityDTOBuilder{ entity: entity, } if assert.NotNil(t, entityDTOBuilder.entity.CommoditiesSold) { assert.Equal(0, len(entityDTOBuilder.entity.CommoditiesSold)) } entityDTOBuilder.Sells(*commType, keystr) assert.Equal(1, len(entityDTOBuilder.entity.CommoditiesSold)) assert.Equal(commType, entityDTOBuilder.entity.CommoditiesSold[0].CommodityType) assert.Equal(*commType, *entityDTOBuilder.entity.CommoditiesSold[0].CommodityType) assert.Equal(keystr, *entityDTOBuilder.entity.CommoditiesSold[0].Key) assert.Equal(&keystr, entityDTOBuilder.entity.CommoditiesSold[0].Key) }