blob: 50c5355dcc17ec86b6c8f462b294d1fc475a937d [file] [log] [blame]
donNewtonAlphab9b85eb2018-08-14 14:28:22 -04001/*
2 Copyright 2017 the original author or authors.
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
17package api_test
18
19import (
20 "fmt"
21 "testing"
22
23 "gerrit.opencord.org/abstract-olt/api"
donNewtonAlpha5234b132018-08-16 14:12:28 -040024 "gerrit.opencord.org/abstract-olt/models/abstract"
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040025 "golang.org/x/net/context"
26)
27
28var clli string
donNewtonAlpha5234b132018-08-16 14:12:28 -040029var slotHostname = "SlotOne"
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040030var ctx context.Context
31var server api.Server
32
33func TestHandler_CreateChassis(t *testing.T) {
34 fmt.Println("in handlerTest_CreateChassis")
35 ctx = context.Background()
36 server = api.Server{}
37 message := &api.AddChassisMessage{CLLI: "my cilli", VCoreIP: "192.168.0.1", VCorePort: 9191}
38 ret, err := server.CreateChassis(ctx, message)
39 if err != nil {
40 t.Fatalf("CreateChassis failed %v\n", err)
41 }
42 clli = ret.DeviceID
43
44}
45func TestHandler_CreateOLTChassis(t *testing.T) {
donNewtonAlpha5234b132018-08-16 14:12:28 -040046 fmt.Println("in handlerTest_CreateChassis")
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040047 message := &api.AddOLTChassisMessage{CLLI: clli, SlotIP: "12.2.2.0", SlotPort: 9191,
donNewtonAlpha5234b132018-08-16 14:12:28 -040048 Hostname: slotHostname, Type: api.AddOLTChassisMessage_edgecore}
donNewtonAlphab9b85eb2018-08-14 14:28:22 -040049 ret, err := server.CreateOLTChassis(ctx, message)
50 if err != nil {
51 t.Fatalf("CreateOLTChassis failed %v\n", err)
52 }
53 fmt.Printf("CreateOLTChassis success %v\n", ret)
54
55}
donNewtonAlpha5234b132018-08-16 14:12:28 -040056func TestHandler_ProvisionOnt(t *testing.T) {
57 ctx = context.Background()
58 server = api.Server{}
59 fmt.Println("in handlerTest_CreateChassis")
60 // this one should succeed
61 message := &api.AddOntMessage{CLLI: clli, SlotNumber: 1, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"}
62 ret, err := server.ProvisionOnt(ctx, message)
63 if err != nil {
64 t.Fatalf("ProvisionOnt failed %v\n", err)
65 }
66 // this one should fail
67 fmt.Println("here")
68 message = &api.AddOntMessage{CLLI: clli, SlotNumber: 2, PortNumber: 3, OntNumber: 2, SerialNumber: "2033029402"}
69 ret, err = server.ProvisionOnt(ctx, message)
70 if err != nil {
71 switch err.(type) {
72 case *abstract.UnprovisonedPortError:
73 fmt.Printf("ProvisionOnt failed as it should with %v\n", err)
74 default:
75 t.Fatalf("ProvsionOnt test failed with %v\n", err)
76 }
77 } else {
78 t.Fatalf("ProvsionOnt should have failed but didn't")
79 }
80 fmt.Printf("ProvisionOnt success %v\n", ret)
81
82}