Skip to content

Commit 15f4882

Browse files
committed
[FAB-9265] Remove Java CC Samples
These are out of date and now belong in the fabric-chaincode-java repo. Also included FAB-9266 here as well as one of the samples is used in the unit tests. Change-Id: Ibea3fa43b45c9a2d3e5c6c1d65ffbdd9bfd2e723 Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
1 parent 990b9e6 commit 15f4882

File tree

29 files changed

+100
-2055
lines changed

29 files changed

+100
-2055
lines changed
+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Copyright IBM Corp. 2016 All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package java_test
18+
19+
import (
20+
"archive/tar"
21+
"bytes"
22+
"compress/gzip"
23+
"testing"
24+
25+
"github.com/hyperledger/fabric/core/chaincode/platforms/java"
26+
pb "github.com/hyperledger/fabric/protos/peer"
27+
"github.com/stretchr/testify/assert"
28+
)
29+
30+
var chaincodePath = "testdata/SimpleSample"
31+
var spec = &pb.ChaincodeSpec{
32+
Type: pb.ChaincodeSpec_JAVA,
33+
ChaincodeId: &pb.ChaincodeID{
34+
Name: "ssample",
35+
Path: chaincodePath},
36+
Input: &pb.ChaincodeInput{
37+
Args: [][]byte{[]byte("f")}}}
38+
39+
var expected = `
40+
ADD codepackage.tgz /root/chaincode
41+
RUN cd /root/chaincode/src && gradle -b build.gradle clean && gradle -b build.gradle build
42+
RUN cp /root/chaincode/src/build/chaincode.jar /root
43+
RUN cp /root/chaincode/src/build/libs/* /root/libs`
44+
45+
func TestValidateSpec(t *testing.T) {
46+
platform := java.Platform{}
47+
48+
err := platform.ValidateSpec(spec)
49+
assert.NoError(t, err)
50+
}
51+
52+
func TestValidateDeploymentSpec(t *testing.T) {
53+
platform := java.Platform{}
54+
err := platform.ValidateSpec(spec)
55+
assert.NoError(t, err)
56+
}
57+
58+
func TestGetDeploymentPayload(t *testing.T) {
59+
platform := java.Platform{}
60+
spec.ChaincodeId.Path = "pathdoesnotexist"
61+
62+
_, err := platform.GetDeploymentPayload(spec)
63+
assert.Contains(t, err.Error(), "code does not exist")
64+
65+
spec.ChaincodeId.Path = chaincodePath
66+
payload, err := platform.GetDeploymentPayload(spec)
67+
assert.NoError(t, err)
68+
assert.NotZero(t, len(payload))
69+
}
70+
71+
func TestGenerateDockerfile(t *testing.T) {
72+
platform := java.Platform{}
73+
cds := &pb.ChaincodeDeploymentSpec{
74+
CodePackage: []byte{}}
75+
76+
_, err := platform.GenerateDockerfile(cds)
77+
assert.Error(t, err)
78+
79+
spec.ChaincodeId.Path = chaincodePath
80+
payload, err := platform.GetDeploymentPayload(spec)
81+
if err != nil {
82+
t.Fatalf("failed to get Java CC payload: %s", err)
83+
}
84+
cds.CodePackage = payload
85+
86+
dockerfile, err := platform.GenerateDockerfile(cds)
87+
assert.NoError(t, err)
88+
assert.Equal(t, expected, dockerfile)
89+
}
90+
91+
func TestGenerateDockerBuild(t *testing.T) {
92+
platform := java.Platform{}
93+
cds := &pb.ChaincodeDeploymentSpec{
94+
CodePackage: []byte{}}
95+
tw := tar.NewWriter(gzip.NewWriter(bytes.NewBuffer(nil)))
96+
97+
err := platform.GenerateDockerBuild(cds, tw)
98+
assert.NoError(t, err)
99+
}

core/chaincode/platforms/java/platform.go

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func getBuildCmd(codePackage []byte) (string, error) {
6767
//ValidateSpec validates the java chaincode specs
6868
func (javaPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
6969
path, err := url.Parse(spec.ChaincodeId.Path)
70+
fmt.Printf("URL: %+v\n", path)
7071
if err != nil || path == nil {
7172
return fmt.Errorf("invalid path: %s", err)
7273
}

core/chaincode/platforms/java/test/java_test.go

-51
This file was deleted.

examples/chaincode/java/.gitignore

-1
This file was deleted.

examples/chaincode/java/Example/build.gradle

-83
This file was deleted.

examples/chaincode/java/Example/pom.xml

-94
This file was deleted.

0 commit comments

Comments
 (0)