1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.creadur.whisker.out.velocity;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.apache.creadur.whisker.model.ByOrganisation;
28 import org.apache.creadur.whisker.model.Descriptor;
29 import org.apache.creadur.whisker.model.License;
30 import org.apache.creadur.whisker.model.Organisation;
31 import org.apache.creadur.whisker.model.Resource;
32 import org.apache.creadur.whisker.model.WithLicense;
33 import org.apache.creadur.whisker.model.WithinDirectory;
34
35 public class DescriptorBuilderForTesting {
36
37 private static final String A_PRIMARY_COPYRIGHT_NOTICE = "Copyright (c) this is primary";
38 String primaryLicenseText = "This is the primary license text";
39 Organisation thirdPartyOrg = new Organisation("third-party", "thirdparty.org", "http://thirdparty.org");
40 License primaryLicense = new License(false, primaryLicenseText, Collections.<String> emptyList(), "example.org", "http://example.org", "Example License");
41 License secondaryLicense = new License(false, "This is the secondary license text", Collections.<String> emptyList(), "example.org:secondary", "http://example.org/secondary", "Example Secondary License");
42
43 String primaryOrgName = "example.org";
44 String primaryNotice = "The primary notice.";
45 Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
46 Map<String, License> licenses = new HashMap<String, License>();
47 Map<String, String> notices = new HashMap<String, String>();
48 Map<String, Organisation> organisations = new HashMap<String, Organisation>();
49 String secondaryCopyright = null;
50 String resourceName;
51 String primaryCopyrightNotice = null;
52 public String sourceUrl = "";
53
54 public DescriptorBuilderForTesting() {
55 resourceName = "resource";
56 primaryLicense.storeIn(licenses);
57 }
58
59 public DescriptorBuilderForTesting withPrimaryLicenseAndOrgInDirectory(String directoryName) {
60 addDirectory(getPrimaryLicense(), primaryOrganisation(), directoryName);
61 return this;
62 }
63
64
65 public DescriptorBuilderForTesting withPrimaryLicenseAndThirdPartyOrgInDirectory(String directoryName) {
66 addDirectory(getPrimaryLicense(), getThirdPartyOrg(), directoryName);
67 return this;
68 }
69
70 public Organisation primaryOrganisation() {
71 return new Organisation(getPrimaryOrgName(), "primary.org", "http://example.org");
72 }
73
74 public Descriptor build() {
75 return new Descriptor(primaryLicense, primaryCopyrightNotice, primaryOrgName,
76 primaryNotice, licenses, notices, organisations, contents);
77 }
78
79 public String getResourceName() {
80 return resourceName;
81 }
82
83 public String getSecondaryCopyright() {
84 return secondaryCopyright;
85 }
86
87 public String getPrimaryOrgName() {
88 return primaryOrgName;
89 }
90
91 public Organisation getThirdPartyOrg() {
92 return thirdPartyOrg;
93 }
94
95 public License getPrimaryLicense() {
96 return primaryLicense;
97 }
98
99 public String getPrimaryLicenseText() {
100 return primaryLicenseText;
101 }
102
103 public void addDirectory(License license, final Organisation org,
104 final String directoryName) {
105 final WithinDirectory withinDirectory = buildDirectory(license, org,
106 directoryName);
107 contents.add(withinDirectory);
108 }
109
110 private Collection<Resource> buildResources() {
111 String noticeId = "notice:id";
112 notices.put(noticeId, "Some notice text");
113 Collection<Resource> resources = new ArrayList<Resource>();
114 resources.add(new Resource(resourceName, noticeId, sourceUrl));
115 return resources;
116 }
117
118 private WithinDirectory buildDirectory(License license,
119 final Organisation org, final String directoryName) {
120 Collection<ByOrganisation> byOrgs = new ArrayList<ByOrganisation>();
121 Collection<Resource> resources = buildResources();
122 byOrgs.add(new ByOrganisation(org, resources));
123
124 Collection<WithLicense> withLicenses = new ArrayList<WithLicense>();
125 Map<String, String> params = Collections.emptyMap();
126 withLicenses.add(new WithLicense(license, secondaryCopyright, params, byOrgs));
127
128 Collection<ByOrganisation> publicDomain = Collections.emptyList();
129
130 final WithinDirectory withinDirectory = new WithinDirectory(directoryName, withLicenses, publicDomain);
131 return withinDirectory;
132 }
133
134 public DescriptorBuilderForTesting withPrimaryCopyrightNotice() {
135 return withPrimaryCopyrightNotice(A_PRIMARY_COPYRIGHT_NOTICE);
136 }
137
138
139 public DescriptorBuilderForTesting withPrimaryCopyrightNotice(String primaryCopyrightNotice) {
140 this.primaryCopyrightNotice = primaryCopyrightNotice;
141 return this;
142 }
143
144 public DescriptorBuilderForTesting withSecondaryLicensePrimaryOrganisationInDirectory(
145 String directoryName) {
146 addDirectory(secondaryLicense, primaryOrganisation(), directoryName);
147 return this;
148 }
149
150 public DescriptorBuilderForTesting withSecondaryCopyrightNotice() {
151 return withSecondaryCopyrightNotice("Copyright (c) this is secondary");
152 }
153
154 public DescriptorBuilderForTesting withSecondaryCopyrightNotice(final String secondaryCopyright) {
155 this.secondaryCopyright = secondaryCopyright;
156 return this;
157 }
158
159 public DescriptorBuilderForTesting withSourceURL() {
160 sourceUrl = "http://example.org/bogus";
161 return this;
162 }
163
164 }