donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package models_test |
| 18 | |
| 19 | import ( |
| 20 | "net" |
| 21 | "testing" |
| 22 | |
| 23 | "gerrit.opencord.org/abstract-olt/internal/pkg/settings" |
| 24 | "gerrit.opencord.org/abstract-olt/models" |
| 25 | "gerrit.opencord.org/abstract-olt/models/abstract" |
| 26 | "gerrit.opencord.org/abstract-olt/models/physical" |
| 27 | ) |
| 28 | |
| 29 | var chassisMap *map[string]*models.ChassisHolder |
| 30 | var clli string |
| 31 | var json []byte |
| 32 | |
| 33 | func TestChassisSerialize_Serialize(t *testing.T) { |
| 34 | //func (chassisHolder ChassisHolder) Serialize() ([]byte, error) { |
| 35 | settings.SetDummy(true) |
| 36 | clli = "TEST_CLLI" |
| 37 | chassisMap = models.GetChassisMap() |
| 38 | abstractChassis := abstract.GenerateChassis(clli, 1, 1) |
donNewtonAlpha | b146639 | 2018-10-02 10:42:05 -0400 | [diff] [blame] | 39 | phyChassis := physical.Chassis{CLLI: clli, XOSAddress: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, Rack: 1, Shelf: 1} |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 40 | chassisHolder := &models.ChassisHolder{AbstractChassis: abstractChassis, PhysicalChassis: phyChassis} |
| 41 | (*chassisMap)[clli] = chassisHolder |
| 42 | sOlt := physical.SimpleOLT{CLLI: clli, Hostname: "slot1", Address: net.TCPAddr{IP: net.ParseIP("127.0.0.1"), Port: 1234}, Parent: &phyChassis} |
| 43 | phyChassis.AddOLTChassis(sOlt) |
| 44 | ports := sOlt.GetPorts() |
| 45 | for i := 0; i < len(ports); i++ { |
| 46 | absPort, _ := chassisHolder.AbstractChassis.NextPort() |
| 47 | |
| 48 | absPort.PhysPort = &ports[i] |
| 49 | //AssignTraits(&ports[i], absPort) |
| 50 | } |
| 51 | var err error |
| 52 | json, err = chassisHolder.Serialize() |
| 53 | if err != nil { |
| 54 | t.Fatalf("TestChassisSerialize_Serialize failed with %v\n", err) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestChassisSerialize_Deserialize(t *testing.T) { |
| 59 | //func (chassisHolder *ChassisHolder) Deserialize(jsonData []byte) error { |
| 60 | chassisHolder := models.ChassisHolder{} |
| 61 | err := chassisHolder.Deserialize(json) |
| 62 | if err != nil { |
| 63 | t.Fatalf("Deserialize threw an error %v\n", err) |
| 64 | } |
| 65 | newJSON, _ := chassisHolder.Serialize() |
| 66 | if string(json) != string(newJSON) { |
| 67 | t.Fatalf("Failed to de-serialize and serialize accurately") |
| 68 | } |
| 69 | } |