Skip to content

Commit

Permalink
Handle breaking change in progression response
Browse files Browse the repository at this point in the history
Progression response now returns an array for each environment
underneath deployments whereas it used to return a single element
  • Loading branch information
matt-richardson committed Apr 8, 2017
1 parent 6d141aa commit c019925
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mjrichardson.teamCity.buildTriggers.Exceptions.InvalidOctopusApiKeyException;
import com.mjrichardson.teamCity.buildTriggers.Exceptions.UnexpectedResponseCodeException;
import com.mjrichardson.teamCity.buildTriggers.InvalidOctopusUrlException;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

Expand Down Expand Up @@ -66,7 +67,14 @@ private Boolean AddDeployments(List releasesAndDeployments) throws java.text.Par
Map deps = (Map) releaseAndDeploymentPairMap.get("Deployments");
for (Object key : deps.keySet()) {
foundDeployment = true;
Environment environment = Environment.Parse((Map) deps.get(key));
Object env = deps.get(key);
Environment environment;

if (env instanceof org.json.simple.JSONArray)
environment = Environment.Parse((Map) ((JSONArray) env).get(0));
else
environment = Environment.Parse((Map) env);

environments.addOrUpdate(environment);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.mjrichardson.teamCity.buildTriggers.Exceptions.InvalidOctopusApiKeyException;
import com.mjrichardson.teamCity.buildTriggers.Exceptions.UnexpectedResponseCodeException;
import com.mjrichardson.teamCity.buildTriggers.InvalidOctopusUrlException;
import com.mjrichardson.teamCity.buildTriggers.Model.ApiProgressionResponse;
import com.mjrichardson.teamCity.buildTriggers.NullOctopusDate;
import com.mjrichardson.teamCity.buildTriggers.OctopusDate;
import com.mjrichardson.teamCity.buildTriggers.ResourceHandler;
Expand Down Expand Up @@ -115,4 +114,16 @@ public void can_parse_progression_response_with_no_recent_successful_deployments
Assert.assertEquals(environments[0].latestDeployment, new OctopusDate(2016, 1, 21, 14, 18, 1, 887));
Assert.assertEquals(environments[0].latestSuccessfulDeployment, new OctopusDate(2016, 1, 21, 13, 35, 27, 179));
}

public void can_parse_progression_response_with_latest_deployment_successful_3_12_1() throws IOException, ParseException, org.json.simple.parser.ParseException, UnexpectedResponseCodeException, URISyntaxException, InvalidOctopusUrlException, InvalidOctopusApiKeyException {
final String json = ResourceHandler.getResource("3.12.1", "api/progression/" + ProjectWithLatestDeploymentSuccessful);
UUID correlationId = UUID.randomUUID();
ApiProgressionResponse sut = new ApiProgressionResponse(json, correlationId);
Assert.assertTrue(sut.haveCompleteInformation);
Assert.assertEquals(sut.environments.size(), 1);
Environment[] environments = sut.environments.toArray();
Assert.assertEquals(environments[0].environmentId, "Environments-1");
Assert.assertEquals(environments[0].latestDeployment, new OctopusDate(2017, 4, 8, 19, 57, 44, 997));
Assert.assertEquals(environments[0].latestSuccessfulDeployment, new OctopusDate(2017, 4, 8, 19, 57, 44, 997));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@

public class ResourceHandler {
public static String getResource(String name) throws IOException {
final String resourceName = "/responses/3.3.0/" + name + ".json";
return getResource("3.3.0", name);
}

public static String getResource(String release, String name) throws IOException {
final String resourceName = "/responses/" + release + "/" + name + ".json";
InputStream resource = ResourceHandler.class.getResourceAsStream(resourceName);
return IOUtils.toString(resource);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"Application": "Octopus Deploy",
"Version": "3.12.1",
"ApiVersion": "3.0.0",
"InstallationId": "eb41c139-8498-49ec-9a44-85a73ecb377f",
"AuthenticationProviders": [
{
"Name": "Octopus",
"IsGuestProvider": false,
"FormsLoginEnabled": true,
"LinkHtml": null,
"Links": {}
}
],
"AutoLoginEnabled": false,
"AnyAuthenticationProvidersSupportPasswordManagement": true,
"ExtensionsCSS": [],
"ExtensionsJavascript": [],
"ExtensionAngularModules": [],
"Links": {
"Self": "/api",
"Accounts": "/api/accounts{/id}{?skip}",
"ActionTemplates": "/api/actiontemplates{/id}{?skip}",
"ActionTemplatesSearch": "/api/actiontemplates/search",
"ActionTemplateLogo": "/api/actiontemplates/{typeOrId}/logo",
"ActionTemplateVersionedLogo": "/api/actiontemplates/{typeOrId}/versions/{version}/logo",
"Alerts": "/api/alerts{/id}{?skip}",
"Artifacts": "/api/artifacts{/id}{?skip,regarding}",
"Channels": "/api/channels{/id}",
"Certificates": "/api/certificates{/id}{?skip,take,search,archived,tenant,firstResult,orderBy}",
"CertificateConfiguration": "/api/configuration/certificates{/id}{?skip}",
"CommunityActionTemplates": "/api/communityactiontemplates{/id}",
"CurrentUser": "/api/users/me",
"CurrentLicense": "/api/licenses/licenses-current",
"CurrentLicenseStatus": "/api/licenses/licenses-current-status",
"Dashboard": "/api/dashboard{?projectId,releaseId,selectedTenants,selectedTags,showAll}",
"DashboardConfiguration": "/api/dashboardconfiguration",
"DashboardDynamic": "/api/dashboard/dynamic{?projects,environments,includePrevious}",
"DeploymentProcesses": "/api/deploymentprocesses{/id}",
"Deployments": "/api/deployments{/id}{?skip,take,projects,environments,tenants,channels,taskState}",
"DiscoverMachine": "/api/machines/discover{?host,port,type,proxyId}",
"Environments": "/api/environments{/id}{?skip,ids}",
"EnvironmentSortOrder": "/api/environments/sortorder",
"Events": "/api/events{/id}{?skip,regarding,regardingAny,user,users,projects,environments,eventGroups,eventCategories,tags,tenants,from,to,internal,fromAutoId,toAutoId}",
"EventCategories": "/api/events/categories{?appliesTo}",
"EventGroups": "/api/events/groups{?appliesTo}",
"ExtensionStats": "/api/serverstatus/extensions",
"ExternalSecurityGroupProviders": "/api/externalsecuritygroupproviders",
"FeaturesConfiguration": "/api/featuresconfiguration",
"Feeds": "/api/feeds{/id}{?skip}",
"Interruptions": "/api/interruptions{/id}{?skip,regarding,pendingOnly}",
"Invitations": "/api/users/invitations",
"LibraryVariables": "/api/libraryvariablesets{/id}{?skip,contentType,ids}",
"Lifecycles": "/api/lifecycles{/id}{?skip}",
"MachinePolicies": "/api/machinepolicies{/id}{?skip}",
"MachineRoles": "/api/machineroles/all",
"Machines": "/api/machines{/id}{?skip,thumbprint,deploymentId,name}",
"MaintenanceConfiguration": "/api/maintenanceconfiguration",
"OctopusServerNodes": "/api/octopusservernodes{/id}",
"Packages": "/api/packages{/id}{?nuGetPackageId,filter,latest,skip,take,includeNotes}",
"PackagesBulk": "/api/packages/bulk{?ids}",
"PackageUpload": "/api/packages/raw{?replace}",
"PermissionDescriptions": "/api/permissions/all",
"ProjectGroups": "/api/projectgroups{/id}{?skip}",
"Projects": "/api/projects{/id}{?skip,ids,clone}",
"ProjectTriggers": "/api/projecttriggers{/id}",
"ProjectPulse": "/api/projects/pulse{?projectIds}",
"Proxies": "/api/proxies{/id}{?skip}",
"Register": "/api/users/register",
"Releases": "/api/releases{/id}{?skip,ignoreChannelRules}",
"Reporting/DeploymentsCountedByWeek": "/api/reporting/deployments-counted-by-week{?projectIds}",
"RepositoryConfiguration": "/api/repository/configuration",
"RetentionPolicies": "/api/retentionpolicies{/id}{?skip}",
"ServerConfiguration": "/api/serverconfiguration",
"ServerConfigurationSettings": "/api/serverconfiguration/settings",
"ServerStatus": "/api/serverstatus",
"SignIn": "/api/users/login{?returnUrl}",
"SignOut": "/api/users/logout",
"Scheduler": "/api/scheduler/{name}/logs{?verbose,tail}",
"SmtpConfiguration": "/api/smtpconfiguration",
"Subscriptions": "/api/subscriptions{/id}{?skip}",
"Tasks": "/api/tasks{/id}{?skip,active,environment,project,name,node,running}",
"Teams": "/api/teams{/id}{?skip}",
"Timezones": "/api/serverstatus/timezones",
"UpgradeConfiguration": "/api/upgradeconfiguration",
"UserOnboarding": "/api/useronboarding",
"UserRoles": "/api/userroles{/id}{?skip}",
"Users": "/api/users{/id}{?skip}",
"Variables": "/api/variables{/id}",
"VariableNames": "/api/variables/names{?project,projectEnvironmentsFilter}",
"VariablesNonPrintableChars": "/api/variables/nonPrintableChars",
"VersionRuleTest": "/api/channels/rule-test{?version,versionRange,preReleaseTag}",
"Web": "/app"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"Environments": [
{
"Id": "Environments-1",
"Name": "Env1"
}
],
"ChannelEnvironments": {
"Channels-8": []
},
"Releases": [
{
"Release": {
"Id": "Releases-1",
"Assembled": "2017-04-08T19:57:38.908+00:00",
"ReleaseNotes": null,
"ProjectId": "Projects-24",
"ChannelId": "Channels-8",
"ProjectVariableSetSnapshotId": "variableset-Projects-24-s-0-9WY86",
"LibraryVariableSetSnapshotIds": [],
"ProjectDeploymentProcessSnapshotId": "deploymentprocess-Projects-24-s-1-MSQP2",
"SelectedPackages": [],
"Version": "0.0.1",
"Links": {
"Self": "/api/releases/Releases-1{?force}",
"Project": "/api/projects/Projects-24",
"Progression": "/api/releases/Releases-1/progression",
"Deployments": "/api/releases/Releases-1/deployments{?skip}",
"DeploymentTemplate": "/api/releases/Releases-1/deployments/template",
"Artifacts": "/api/artifacts?regarding=Releases-1",
"ProjectVariableSnapshot": "/api/variables/variableset-Projects-24-s-0-9WY86",
"ProjectDeploymentProcessSnapshot": "/api/deploymentprocesses/deploymentprocess-Projects-24-s-1-MSQP2",
"Web": "/app#/releases/Releases-1",
"SnapshotVariables": "/api/releases/Releases-1/snapshot-variables",
"Defects": "/api/releases/Releases-1/defects",
"ReportDefect": "/api/releases/Releases-1/defects",
"ResolveDefect": "/api/releases/Releases-1/defects/resolve"
}
},
"Channel": {
"Id": "Channels-8",
"Name": "Default",
"Description": null,
"ProjectId": "Projects-24",
"LifecycleId": null,
"IsDefault": true,
"Rules": [],
"TenantTags": [],
"Links": {
"Self": "/api/channels/Channels-8",
"Releases": "/api/channels/Channels-8/releases",
"Project": "/api/projects/Projects-24"
}
},
"Deployments": {
"Environments-1": [
{
"Id": "Deployments-1",
"ProjectId": "Projects-24",
"EnvironmentId": "Environments-1",
"ReleaseId": "Releases-1",
"DeploymentId": "Deployments-1",
"TaskId": "ServerTasks-7",
"TenantId": null,
"ChannelId": null,
"ReleaseVersion": "0.0.1",
"Created": "2017-04-08T19:57:44.997+00:00",
"QueueTime": "2017-04-08T19:57:44.991+00:00",
"CompletedTime": "2017-04-08T19:57:49.903+00:00",
"State": "Success",
"HasPendingInterruptions": false,
"HasWarningsOrErrors": false,
"ErrorMessage": "",
"Duration": "5 seconds",
"IsCurrent": true,
"IsPrevious": false,
"IsCompleted": true,
"Links": {
"Self": "/api/deployments/Deployments-1",
"Release": "/api/releases/Releases-1",
"Tenant": "/api/tenants/",
"Task": "/api/tasks/ServerTasks-7"
}
}
]
},
"NextDeployments": [],
"HasUnresolvedDefect": false,
"ReleaseRetentionPeriod": null,
"TentacleRetentionPeriod": null
}
],
"Links": {}
}

0 comments on commit c019925

Please sign in to comment.