Skip to content

Commit 8aebd41

Browse files
bug[TW26880]: Resolve resource leaks
Signed-off-by: Baily Roberts <[email protected]>
1 parent a15c4b6 commit 8aebd41

File tree

3 files changed

+53
-47
lines changed

3 files changed

+53
-47
lines changed

plugins/org.eclipse.osee.ats.ide.integration.tests/src/org/eclipse/osee/ats/ide/integration/tests/orcs/rest/applic/ApiKeyEndpointTest.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ public void testKeyLifeCycle() {
137137
keyValue.length());
138138

139139
// Check Use
140-
Response branchesResponse = getRequestWithAuthorization("/orcs/branches", keyValue);
141-
assertEquals("Call with API Key was not successful with status: " + branchesResponse.getStatus(),
142-
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
143-
140+
try (Response branchesResponse = getRequestWithAuthorization("/orcs/branches", keyValue);) {
141+
assertEquals("Call with API Key was not successful with status: " + branchesResponse.getStatus(),
142+
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
143+
}
144144
// Revoke
145-
Response response = apiKeyEndpoint.revokeApiKey(Long.parseLong(uid));
146-
assertEquals(Family.SUCCESSFUL, response.getStatusInfo().getFamily());
147-
145+
try (Response response = apiKeyEndpoint.revokeApiKey(Long.parseLong(uid));) {
146+
assertEquals(Family.SUCCESSFUL, response.getStatusInfo().getFamily());
147+
}
148148
// Check ApiKey is gone
149149
apiKeys = apiKeyEndpoint.getApiKeys().readEntity(apiKeyList);
150150

@@ -163,11 +163,11 @@ public void testKeyExpiration() {
163163
String keyValue = uidAndValue.get("keyValue");
164164

165165
// Check Use
166-
Response branchesResponse = getRequestWithAuthorization("/orcs/branches", keyValue);
167-
assertNotEquals(
168-
"Call with with expired API Key was unexpectedly successful with status: " + branchesResponse.getStatus(),
169-
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
170-
166+
try (Response branchesResponse = getRequestWithAuthorization("/orcs/branches", keyValue);) {
167+
assertNotEquals(
168+
"Call with with expired API Key was unexpectedly successful with status: " + branchesResponse.getStatus(),
169+
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
170+
}
171171
// Create Key With Same Day Expiration
172172
scopes = setKeyScopes(new int[] {2});
173173
keyToCreate = new ApiKey("Key 1", scopes, currentDateString, currentDateString, "");
@@ -176,19 +176,21 @@ public void testKeyExpiration() {
176176
keyValue = uidAndValue.get("keyValue");
177177

178178
// Check Use
179-
branchesResponse = getRequestWithAuthorization("/orcs/branches", keyValue);
180-
assertEquals(
181-
"API Key call with same day expiration unexpectedly failed with status: " + branchesResponse.getStatus(),
182-
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
179+
try (Response branchesResponse = getRequestWithAuthorization("/orcs/branches", keyValue);) {
180+
assertEquals(
181+
"API Key call with same day expiration unexpectedly failed with status: " + branchesResponse.getStatus(),
182+
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
183+
}
183184
}
184185

185186
@Test
186187
public void testInvalidKey() {
187188
// Check Use
188-
Response branchesResponse = getRequestWithAuthorization("/orcs/branches", "invalid");
189-
assertNotEquals(
190-
"Call with with expired API Key was unexpectedly successful with status: " + branchesResponse.getStatus(),
191-
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
189+
try (Response branchesResponse = getRequestWithAuthorization("/orcs/branches", "invalid");) {
190+
assertNotEquals(
191+
"Call with with expired API Key was unexpectedly successful with status: " + branchesResponse.getStatus(),
192+
Family.SUCCESSFUL, branchesResponse.getStatusInfo().getFamily());
193+
}
192194
}
193195

194196
@Test

plugins/org.eclipse.osee.ats.ide.integration.tests/src/org/eclipse/osee/ats/ide/integration/tests/orcs/rest/applic/TransactionEndpointTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,9 @@ private void purge(TransactionToken transactionId) throws Exception {
720720
public void testPurgeUnusedBackingData() {
721721
JdbcClient client = AtsApiService.get().getJdbcService().getClient();
722722
int initialRowCount = client.fetch(0, "SELECT count(1) FROM osee_attribute");
723-
transactionEndpoint.purgeUnusedBackingDataAndTransactions();
723+
try (Response response = transactionEndpoint.purgeUnusedBackingDataAndTransactions();) {
724+
//
725+
}
724726
int afterRowCount = client.fetch(0, "SELECT count(1) FROM osee_attribute");
725727
Assert.assertNotEquals(initialRowCount, afterRowCount);
726728
}

plugins/org.eclipse.osee.define/src/org/eclipse/osee/define/operations/reports/FeatureImpactStreamingOutput.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -181,35 +181,37 @@ public void write(OutputStream output) {
181181
final var baselineDocMsWordPreviewRequestData =
182182
new PublishingRequestData(FeatureImpactStreamingOutput.publishingTemplateRequest,
183183
baselineDocRendererOptions, List.of(previewHeadArtifactIdentifier));
184-
final var workingDocStream = this.publishingOperations.msWordPreview(
185-
workingDocMsWordPreviewRequestData).getDataHandler().getInputStream();
186-
final var baselineDocStream = this.publishingOperations.msWordPreview(
187-
baselineDocMsWordPreviewRequestData).getDataHandler().getInputStream();
188-
workingDocStream.mark(0);
189-
boolean equal = IOUtils.contentEquals(workingDocStream, baselineDocStream);
190-
baselineDocStream.close();
191-
if (!equal) {
192-
PrintWriter docWriter = new PrintWriter(writer);
193-
workingDocStream.reset();
184+
try (final var workingDocStream = this.publishingOperations.msWordPreview(
185+
workingDocMsWordPreviewRequestData).getDataHandler().getInputStream();) {
186+
try (final var baselineDocStream = this.publishingOperations.msWordPreview(
187+
baselineDocMsWordPreviewRequestData).getDataHandler().getInputStream();) {
188+
workingDocStream.mark(0);
189+
boolean equal = IOUtils.contentEquals(workingDocStream, baselineDocStream);
190+
baselineDocStream.close();
191+
if (!equal) {
192+
PrintWriter docWriter = new PrintWriter(writer);
193+
workingDocStream.reset();
194194

195-
zipOut.putNextEntry(new ZipEntry(viewEntry.getKey() + ".xml"));
196-
try {
197-
InputStreamReader reader = new InputStreamReader(workingDocStream, "UTF-8");
198-
BufferedReader br = new BufferedReader(reader);
199-
String l;
200-
while ((l = br.readLine()) != null) {
201-
docWriter.println(l);
195+
zipOut.putNextEntry(new ZipEntry(viewEntry.getKey() + ".xml"));
196+
try {
197+
InputStreamReader reader = new InputStreamReader(workingDocStream, "UTF-8");
198+
BufferedReader br = new BufferedReader(reader);
199+
String l;
200+
while ((l = br.readLine()) != null) {
201+
docWriter.println(l);
202+
}
203+
docWriter.flush();
204+
br.close();
205+
reader.close();
206+
workingDocStream.close();
207+
} catch (IOException ex) {
208+
OseeCoreException.wrapAndThrow(ex);
209+
}
210+
zipOut.closeEntry();
211+
} else {
212+
workingDocStream.close();
202213
}
203-
docWriter.flush();
204-
br.close();
205-
reader.close();
206-
workingDocStream.close();
207-
} catch (IOException ex) {
208-
OseeCoreException.wrapAndThrow(ex);
209214
}
210-
zipOut.closeEntry();
211-
} else {
212-
workingDocStream.close();
213215
}
214216
}
215217
}

0 commit comments

Comments
 (0)