Exemplo n.º 1
0
func TestConvertCompactMetadata(t *testing.T) {
	body := ioutil.NopCloser(strings.NewReader(retsStart + system + resource + class + table + lookup + lookupType + retsEnd))
	compact, err := rets.ParseMetadataCompactResult(body)
	testutils.Ok(t, err)

	msystem, err := AsStandard(*compact).Convert()
	testutils.Ok(t, err)

	testutils.Equals(t, "MLS System", msystem.System.Description)
	testutils.Equals(t, "1.12.30", string(msystem.Version))
	testutils.Equals(t, "The System is provided to you by Systems.", msystem.System.Comments)

	mresource := msystem.System.MResource
	testutils.Equals(t, "1.12.30", string(mresource.Version))
	testutils.Equals(t, 2, len(mresource.Resource))

	mlookup := mresource.Resource[1].MLookup
	testutils.Equals(t, "1.12.29", string(mlookup.Version))
	testutils.Equals(t, 4, len(mlookup.Lookup))

	mlookupType := mlookup.Lookup[0].MLookupType
	testutils.Equals(t, "1.12.29", string(mlookupType.Version))
	testutils.Equals(t, 4, len(mlookupType.LookupType))

	agent := mresource.Resource[1]
	testutils.Equals(t, 2, len(agent.MClass.Class))
	testutils.Equals(t, "Agent", string(agent.ResourceID))
	testutils.Equals(t, "1.12.29", string(agent.MClass.Version))

}
Exemplo n.º 2
0
// GetCompactIncrementalMetadata retrieve the RETS Compact metadata from the server
func (ic *IncrementalCompact) Load(sess rets.Requester, ctx context.Context, url string) error {
	// extract an id'd subesection of metadata
	get := func(id, mtype string) (*rets.CompactMetadata, error) {
		if id == "" {
			id = "0"
		}
		req := rets.MetadataRequest{
			URL:    url,
			Format: "COMPACT",
			MType:  mtype,
			ID:     id,
		}
		reader, er := rets.MetadataStream(sess, ctx, req)
		if er != nil {
			return nil, er
		}
		return rets.ParseMetadataCompactResult(reader)
	}
	msys, err := get("", metadata.MISystem.Name)
	if err != nil {
		return err
	}
	ic.Response = msys.Response
	ic.MSystem = msys.MSystem
	ic.Elements = map[string][]rets.CompactData{}
	// fmt.Printf("compact system: %v\n", compact)
	cds, err := ic.extractChildren(get, []string{}, metadata.MISystem)
	if err != nil {
		return err
	}
	for _, cd := range cds {
		// extract children from this element and put in the system elem
		ic.Elements[cd.Element] = append(ic.Elements[cd.Element], cd)
	}
	return nil
}