Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions src/main/java/jpos/config/simple/AbstractRegPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,34 +408,39 @@ private InputStream findFileInJarZipFiles( String fileName, List<String> jarZipF
{
InputStream is = null;

for( int i = 0; i < jarZipFilesList.size(); ++i )
for (String jarZipFileName : jarZipFilesList)
{
String jarZipFileName = jarZipFilesList.get( i );

try (ZipFile zipFile = new ZipFile( jarZipFileName ))
try
{
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();

while( zipEntries.hasMoreElements() )
{
ZipEntry zipEntry = zipEntries.nextElement();
String entryName = zipEntry.getName();

if( entryName.endsWith( fileName ) )
{
is = new BufferedInputStream( zipFile.
getInputStream( zipEntry ) );
break;
}
}
ZipFile zipFile = new ZipFile( jarZipFileName );
try {

Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();

while( zipEntries.hasMoreElements() )
{
ZipEntry zipEntry = zipEntries.nextElement();
String entryName = zipEntry.getName();

if( entryName.endsWith( fileName ) )
{
is = new BufferedInputStream( zipFile.
getInputStream( zipEntry ) );
return is;
}
}
}
finally {
if (is == null) {
zipFile.close();
}
}
}
catch( Exception e )
{
tracer.println( "findInJarZipFiles: Exception.message=" +
e.getMessage() );
}

if( is != null ) break;
}

return is;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void save(@SuppressWarnings("rawtypes") Enumeration entries, String fileN

@Override
public void load() {
try (InputStream is = isPopulatorFileDefined() ? new FileInputStream(DEFAULT_XML_FILE_NAME) : getPopulatorFileIS()) {
try (InputStream is = isPopulatorFileDefined() ? getPopulatorFileIS() : new FileInputStream(DEFAULT_XML_FILE_NAME) ) {
load(is);
} catch (Exception e) {
tracer.println("Error while loading populator file Exception.message: " + e.getMessage());
Expand Down
104 changes: 104 additions & 0 deletions src/test/java/jpos/config/simple/xml/JavaxRegPopulatorTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import jpos.config.*;
import jpos.config.simple.*;
import jpos.loader.JposServiceLoader;
import jpos.test.*;
import jpos.util.JposPropertiesConst;

/**
* A JUnit TestCase for the Loading/saving XML entries
Expand Down Expand Up @@ -287,6 +289,108 @@ public void testGetLastLoadException()
emptyTest();
}

public void testLoadDefault() throws Exception
{
Properties jclProps = new Properties();
jclProps.put( "jpos.util.tracing.TurnOnAllNamedTracers", JPOS_UTIL_TRACING_VALUE );
createPropFile( jclProps );

JposServiceLoader.getManager().getProperties().loadJposProperties();

javaxRegPopulator.load();

assertTrue("Default jpos.xml is not found",
javaxRegPopulator.getLastLoadException() instanceof FileNotFoundException);

restorePropFile();

}

public void testLoadCustomNonExisting() throws Exception
{
Properties jclProps = new Properties();
jclProps.put( "jpos.util.tracing.TurnOnAllNamedTracers", JPOS_UTIL_TRACING_VALUE );
jclProps.put(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "" + System.currentTimeMillis() + ".xml" );
createPropFile( jclProps );

JposServiceLoader.getManager().getProperties().loadJposProperties();

javaxRegPopulator.load();

assertTrue("Custom XML populator file not found",
javaxRegPopulator.getLastLoadException() instanceof FileNotFoundException);

restorePropFile();

}

public void testLoadCustomPopulator() throws Exception
{
Properties jclProps = new Properties();
jclProps.put( "jpos.util.tracing.TurnOnAllNamedTracers", JPOS_UTIL_TRACING_VALUE );
jclProps.put(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, JCL_JUNIT_XML_FILE_NAME );
createPropFile( jclProps );

JposServiceLoader.getManager().getProperties().loadJposProperties();

List<JposEntry> v1 = new ArrayList<>();
try
{
javaxRegPopulator.save( Collections.enumeration(v1), JCL_JUNIT_XML_FILE_NAME );
javaxRegPopulator.load();

assertNull(javaxRegPopulator.getLastLoadException());

@SuppressWarnings("unchecked")
Enumeration<JposEntry> entries = javaxRegPopulator.getEntries();

assertTrue( "Expected an empty set of entries...", JUnitUtility.isIdentical( entries, Collections.enumeration(v1) ) );
assertTrue( "Expected an empty set of entries...", JUnitUtility.isEquals( entries, Collections.enumeration(v1) ) );

//Add some entries and save and load
JposEntry entry1 = createJposEntry( "entry1", "com.xyz.jpos.XyzJposServiceInstanceFactory",
"com.xyz.jpos.LineDisplayService", "Xyz, Corp.",
"http://www.javapos.com", "LineDisplay", "1.4a",
"Virtual LineDisplay JavaPOS Service",
"Example virtual LineDisplay JavaPOS Service from virtual Xyz Corporation",
"http://www.javapos.com" );


v1.clear();
v1.add( entry1 );

javaxRegPopulator.save( Collections.enumeration(v1) );
javaxRegPopulator.load( );

assertNull(javaxRegPopulator.getLastLoadException());

@SuppressWarnings("unchecked")
Enumeration<JposEntry> entries2 = javaxRegPopulator.getEntries();

assertTrue( "Expected 1 entry...", JUnitUtility.isEquals( entries2, Collections.enumeration(v1) ) );

//Remove entries save and load reg
v1.remove( entry1 );

javaxRegPopulator.save( Collections.enumeration(v1) );
javaxRegPopulator.load( );

assertNull(javaxRegPopulator.getLastLoadException());

@SuppressWarnings("unchecked")
Enumeration<JposEntry> entries3 = javaxRegPopulator.getEntries();

assertTrue( "Expected 1 entries...", JUnitUtility.isEquals( entries3, Collections.enumeration(v1) ) );
}
catch( Exception e )
{
fail( "Unexpected exception message = " + e.getMessage() );
}

restorePropFile();

}

//-------------------------------------------------------------------------
// Instance variables
//
Expand Down