-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Buuhuu/bugfix/SLING-7358
SLING-7358: FileDistributionPackageBuilder temp directory fallback
- Loading branch information
Showing
2 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...java/org/apache/sling/distribution/packaging/impl/FileDistributionPackageBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.sling.distribution.packaging.impl; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.apache.sling.distribution.DistributionRequest; | ||
import org.apache.sling.distribution.common.DistributionException; | ||
import org.apache.sling.distribution.packaging.DistributionPackage; | ||
import org.apache.sling.distribution.serialization.DistributionContentSerializer; | ||
import org.apache.sling.distribution.serialization.DistributionExportOptions; | ||
import org.junit.Test; | ||
|
||
public class FileDistributionPackageBuilderTest { | ||
|
||
@Test | ||
public void testDefaultTempDirectory() throws DistributionException, IOException { | ||
FileDistributionPackageBuilder builder = new FileDistributionPackageBuilder("test", new TestSerializer(), null, null, new String[0], | ||
new String[0]); | ||
DistributionPackage createdPackage = builder.createPackageForAdd(mock(ResourceResolver.class), mock(DistributionRequest.class)); | ||
|
||
try { | ||
assertNotNull(createdPackage.createInputStream()); | ||
DistributionPackage gotPackage = builder.getPackageInternal(mock(ResourceResolver.class), createdPackage.getId()); | ||
assertNotNull(gotPackage.createInputStream()); // this will throw an exception when the file doesn't exist | ||
} finally { | ||
createdPackage.delete(); | ||
} | ||
} | ||
|
||
class TestSerializer implements DistributionContentSerializer { | ||
|
||
@Override public void exportToStream(ResourceResolver resourceResolver, DistributionExportOptions exportOptions, | ||
OutputStream outputStream) throws DistributionException { | ||
try { | ||
outputStream.write("test".getBytes()); | ||
} catch (IOException ex) { | ||
throw new DistributionException(ex); | ||
} | ||
} | ||
|
||
@Override public void importFromStream(ResourceResolver resourceResolver, InputStream inputStream) throws DistributionException { | ||
throw new DistributionException("unsupported"); | ||
} | ||
|
||
@Override public String getName() { | ||
return "test"; | ||
} | ||
|
||
@Override public boolean isRequestFiltering() { | ||
return true; | ||
} | ||
} | ||
} |