0

I am having some problems with simple cloud storage (simplecloud). When I run with Maven the console outputs following error :

java.io.FileNotFoundException: \var\key (The system cannot find the path specified)

Source code is here : src git

However it exists in the directory as shown here :

Any ideas?

Thanks in advance

enter image description here

POM :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pliablematter</groupId>
<artifactId>simple-cloud-storage</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Simple Cloud Storage</name>
<description>A simple wrapper around the Google Cloud Storage API</description>

<dependencies>
    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-jackson2</artifactId>
        <version>1.15.0-rc</version>
    </dependency>

    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-storage</artifactId>
        <version>v1beta2-rev6-1.15.0-rc</version>
    </dependency>



    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>LATEST</version>
        <scope>test</scope>
    </dependency>
</dependencies>

David
  • 840
  • 6
  • 17
  • 37
  • From junit you should use a particular version and **NOT** `LATEST` cause if a new release comes out your build might fail. So in other words your build is not reproducible. – khmarbaise Feb 24 '14 at 07:54
  • @David , DId you resolve this problem?. I run into the same problem.Can you please give me solution for this issue? – BABU K Apr 23 '14 at 11:37
  • Hey when I put the key in the folder : /simple-cloud-storage/src/main/resources/var/ and did a clean maven build the project was running and I had a JAR file which worked. Sometimes the tests doesn't pass because you are limited to do x requests per second but 1 out of 10 it worked I thought. – David Apr 23 '14 at 20:28

3 Answers3

0

I suggest you post the related code snippet in your CreateBucketTest.

I believe in your test you are opening a file \var\key. Obviously this is going to cause problem because the file you are thinking of is not really located at \var\key

Some suggestions to you:

  1. instead of reading from absolute path, see if you can change it to opening stream for class path resources.

  2. Put your key file under src/main/test/resources. Assume you put it under src/main/test/resources/cloudkey/key

  3. With the above setup, when you run your test, the key file will be under the classpath at location /cloudkey/key


Edit:

After reading a bit on your code, here are some suggestions:

First, your getStorage relies on system property which is not very test friendly. Consider writing your code in a more test-friendly way

However I believe you are not going to refactor your code anyway, here is one way you can do:

  1. put key in /src/test/resources. By doing so, when compiled, key will be put to BASE_DIR/target/test-classes/key.
  2. Here I assume you will have only 1 key for all your tests. What you need to do is to set the system property private.key.path with the correct path of key. You can do so by configuring surefire plugin : http://maven.apache.org/surefire/maven-surefire-plugin/examples/system-properties.html. Add a systemPropertyVariables private.key.path with value ${project.build.testOutputDirectory}/key. By doing so, when your test is running, the sys property private.key.path will be set with the correct value, so that your test should run fine.
Adrian Shum
  • 38,812
  • 10
  • 83
  • 131
  • I updated the post. I did what you suggested but still running on the error. I even placed it in every map of the project but still no effect. – David Feb 24 '14 at 11:32
  • They key is how you are reading the file. it is not going to work by placing the file everywhere. Try to understand what happen to the files you put under `src/` and how it is make available to your tests – Adrian Shum Feb 28 '14 at 02:06
0

Make sure your \var\key directory is present in the target directory that Maven creates for the build. I'll go out on a limb and guess that it's probably not there now. If you have to have that \var\key in a non-standard place, you can use the Maven Resources Plugin to copy it into the target directory. As @Adrian Shum suggests, test\resources would be a standard place for Maven to look to find it.

EDIT:

Seems like you wanted to explore this option, so here's how you might use the Maven Resources Plugin in your Maven POM...

Inside the plugins node under build, add:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.6</version>
</plugin>

Then after the plugins node again inside build, add the directory or directories you need to copy over to target, for example:

<resources>
    <resource><directory>src/main/resources</directory></resource>
</resources>
<testResources>
    <testResource><directory>src/var/key</directory></testResource>
    <testResource><directory>src/test/resources</directory></testResource>
</testResources>
unigeek
  • 2,656
  • 27
  • 27
  • I just placed my var folder into target directory but when running the folder goes away and reports come in place. – David Feb 24 '14 at 11:58
  • Yes, this is why I mentioned that you should use the Maven Resources Plugin to copy the resources to the target directory. Wouldn't bother doing that if you are able to relocate the item you need to the test/resources tree, however--I find with Maven that I really don't like to fight it. – unigeek Feb 24 '14 at 13:30
  • Added example in case you'll have to use the maven-resources-plugin. You may need to fiddle with the directory you have it copy for you--maybe you want src/var rather than src/var/key. Just get it synced up with the code so it can see a resource that exists in the target directory. – unigeek Feb 24 '14 at 14:01
0

Remove the initial \. Also, as pointed out by the others, as this is obviously a test key (judging by the name), you should place it under src/test/resources/var/key and change your code to look for just var/key/test.p12.

carlspring
  • 31,231
  • 29
  • 115
  • 197